当使用Mirror API时,我偶尔会从几个API调用中(包括
它似乎是随机发生的,可能是在一段时间不使用API后发生的。以下是一个样本堆栈跟踪:
timeline().insert
和timeline.list
)随机收到"BadStatusLine"异常。从在python中遍历SO寻找类似问题的结果来看,我怀疑这是来自服务器的某种格式不正确的响应。它似乎是随机发生的,可能是在一段时间不使用API后发生的。以下是一个样本堆栈跟踪:
Traceback (most recent call last):
File "service.py", line 61, in receive_message
self.process_user_chat(msg)
File "service.py", line 304, in process_user_chat
self.upsert_timeline_item(sourceItemId, body)
File "service.py", line 86, in upsert_timeline_item
new_item = self.glass_service.timeline().insert(body=body).execute()
File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 128, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/apiclient/http.py", line 676, in execute
body=self.body, headers=self.headers)
File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 128, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 494, in new_request
self._refresh(request_orig)
File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 653, in _refresh
self._do_refresh_request(http_request)
File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 682, in _do_refresh_request
self.token_uri, method='POST', body=body, headers=headers)
File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1570, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1317, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1286, in _conn_request
response = conn.getresponse()
File "/usr/lib/python2.7/httplib.py", line 1034, in getresponse
response.begin()
File "/usr/lib/python2.7/httplib.py", line 407, in begin
version, status, reason = self._read_status()
File "/usr/lib/python2.7/httplib.py", line 371, in _read_status
raise BadStatusLine(line)
BadStatusLine: ''
这段代码大部分时间都能正常工作,但是偶尔会出现以下响应。
更新:我的代码创建了Google API类并在服务期间使用它们。一旦到了续订我的oauth2
令牌(1小时)的时间,我就会遇到这个错误一两次,然后它又可以正常工作了。我能够重构我的代码,使其在每个请求时都创建API类,问题已经解决。这似乎是Google API中已知的一个bug,请参见Anthony Tuininga的选定答案以获取更多信息。