所以我正在VBA中执行JSON拉取,并且正文异常长。在VBA中,最大字符串长度(可能是API)最大,因此我编写了一个脚本,将其连接到正文。当我运行代码时,我的responseText出现错误(运行时错误'1002'-语法错误),我还在H.responseText之后进行了Debug.Print操作,并给出了500错误,这使我不得不承担我的身体有毛病吗?有人可以阅读我的脚本以查看代码中是否有错误吗?如果你们有更好的解决方案,那么我很想知道!谢谢
print("Input filename")
sfilepath = input()
ret = ""
q = 0
with open(sfilepath, 'r') as data:
stext = data.read()
print(f"Proceeding with file {sfilepath} that is {len(stext)} characters long")
while len(stext) >= 128:
if q == 0:
ret += 'Body = "' + stext[:128] + '"\n'
else:
ret += 'Body = Body & "' + stext[:128] + '"\n'
stext = stext[128:]
q += 1
if len(stext) > 0:
ret += 'Body = Body & "' + stext + '"'
data.close()
with open('output.txt','w') as data:
data.writelines(ret)
data.close()
print("Finished processing and saved to output.txt")
input()
答案 0 :(得分:0)
尝试更改您的代码:
print(f"Proceeding with file {sfilepath} that is {len(stext)} characters long")
对此:
print("Proceeding with file "+ sfilepath +" that is " + str(len(stext))+ " characters long")
希望可以解决