在使用python请求运行脚本时,我收到一个分块编码错误,我想知道为什么会收到这个错误。在
当我做resp.encoding
我把它拿回来None
我目前没有在我的脚本中使用任何SSL认证验证,所以我也会收到不安全的请求警告。在
for attachment in attachments:
if attachment['type'] == 'Form':
continue
# create insertcursor row
row = cursorPointData.newRow()
pprint(attachments)
for key in attachment:
pprint(key)
pprint(attachment[key])
row.setValue(key, attachment[key])
# Download file
guid = attachment['guid']
resp = requests.get(
'https:...' + guid,
headers={'Authorization': 'Bearer ' + token},
stream=True,
verify=False
)
contentType = resp.headers['Content-Type']
contentLength = int(resp.headers['content-length'])
pprint('contentLength = ' + str(contentLength))
extension = contentType.split('/')[1]
filename = '{0}.{1}'.format(guid, extension)
output_path = os.path.join(attachmentDir, filename)
attachmentPath = os.path.join("filepath", filename)
with open(output_path, 'wb') as f:
for chunk in resp.iter_content(chunk_size=None):
if chunk:
f.write(chunk)
f.flush() #flush the data to file
os.fsync(f.fileno()) #force the file write and free memory
row.setValue('attachmentPath', attachmentPath)
cursorPointData.insertRow(row)
del cursorPointData, row
我查看了Chrome开发工具的网络标签,得到的状态是200。但是在Firefox开发工具中,我得到了301状态:“永久移动”。在
结果我给请求输入了错误的url,需要将url更改为重定向到的更新版本。在
发现您可以使用python请求库中的
response.history
来查找任何重定向问题。在现在,我返回
utf-8
作为响应编码,而不是none。在把这个留在这里以防其他人遇到同样的问题。在
相关问题 更多 >
编程相关推荐