[英]AttributeError when using requests.post() in `with` statement
A / C python請求文檔 ,with語句可與請求一起使用,以提高速度。
將request.get(' http://httpbin.org/get',stream = True)設置為r:#在此處處理響應。
那么為什么返回“屬性錯誤”呢?
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__
碼:
with requests.post(url,headers=headers,data=data,stream=True) as post_res:
print(b'Name' in post_res.content)
附注:如果沒有“ with”語句,此方法可以正常工作。
AFAICS僅針對GET
請求(而非POST
記錄了上下文管理器。 這樣做確實是有道理的,因為POST
並不是獨立的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.