I receive a Chunked Encoding Error when running my script using python requests, and I am wondering why I could be receiving this error.
When I do resp.encoding
I get it back None
I am currently not using any SSL certification verification in my script and so I get Insecure Requests Warnings as well.
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