我正在發送請求並將其響應對象接收到掛鉤函數中。 有時候,我發送了一個新的請求,該請求反過來調用發送請求的函數(每個請求都有一個新的線程)。使用請求中的鉤子的AttributeError Python包
,在請求創建下列除外模塊本身:
Exception in thread Thread-103:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/api.py", line 272, in thread_func
r = self.session.post(url, data=params, headers=headers, timeout=60, hooks=dict(response=self.http_callback))
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 425, in post
return self.request('POST', url, data=data, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 383, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 494, in send
if r.history:
AttributeError: 'bool' object has no attribute 'history'
我覺得很奇怪。你知道會發生什麼嗎?
注:我看了一下這個問題,但我的問題是不同的:Problems with hooks using Requests Python package
你已經返回了一個布爾值,其中'requests'需要一個響應對象。但是,如果沒有你的代碼,就沒有什麼更有意義的東西了 –
定義了self.http_callback? – huu