AttributeError when using requests.post() in `with` statement

Viewed 1337

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.

1 Answers
Related