The chunk-size is not working in python requests
Question:
Import requests
Headers = {'range':'bytes=0-11'}
rrequests = requests.get('https://httpbin.org/image/webp', stream=True, headers=headers)
with open('testfile.jpg', 'wb') as file:
For i in rrequests.iter_content(chunk-size==8):
write_file = file.write(i)
print(write_file)
result :
`name 'chunk' is not defined`
Why do i get name error chunk is not defined ?
Answers:
You’re not using the correct syntax for iter_content()
.
Try this instead :
import requests
headers = {'range':'bytes=0-11'}
rrequests = requests.get('https://httpbin.org/image/webp', stream=True, headers=headers)
with open('testfile.jpg', 'wb') as file:
for i in rrequests.iter_content(chunk_size=8):
write_file = file.write(i)
print(write_file)
Import requests
Headers = {'range':'bytes=0-11'}
rrequests = requests.get('https://httpbin.org/image/webp', stream=True, headers=headers)
with open('testfile.jpg', 'wb') as file:
For i in rrequests.iter_content(chunk-size==8):
write_file = file.write(i)
print(write_file)
result :
`name 'chunk' is not defined`
Why do i get name error chunk is not defined ?
You’re not using the correct syntax for iter_content()
.
Try this instead :
import requests
headers = {'range':'bytes=0-11'}
rrequests = requests.get('https://httpbin.org/image/webp', stream=True, headers=headers)
with open('testfile.jpg', 'wb') as file:
for i in rrequests.iter_content(chunk_size=8):
write_file = file.write(i)
print(write_file)