A/C python requests documentation, with statement can be used with requests for better speed.
with requests.get('http://httpbin.org/get', stream=True) as r: # Do things with the response here.
So why is this returning 'Attribute error'?
Traceback (most recent call last):
File "<pyshell#101>", line 1, in <module>
with requests.post(url,headers=headers,data=data,stream=True) as post_res:
AttributeError: __exit__
code:
with requests.post(url,headers=headers,data=data,stream=True) as post_res:
    print(b'Name' in post_res.content)
P.S. This is working fine without 'with' statement.
AFAICS a context manager is documented only for GET requests, not POST. That does make sense since POST is not indempotent anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With