Google Mirror API抛出BadStatusLine异常(Python)
作者:互联网
使用Mirror API时,我从多个API调用中随机获取了“ BadStatusLine”异常,包括timeline().insert和timeline.list.从围绕SO寻求类似python中的问题的方式开始,我怀疑这是服务器的某种形式的错误响应.
它似乎是随机发生的,并且可能在一段时间不使用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中的已知错误,请参阅Anthony Tuininga的选定答案以获取更多信息.
解决方法:
此问题似乎是一个已知问题.我自己一直都经历过.如果单个文件的上传时间超过1小时,则会发生此错误.如果上传了其他文件,则API会正确刷新令牌.有关更多信息,请参见此错误.显然,它尚未修复,尚无关于何时修复的ETA.
标签:google-mirror-api,python,google-glass 来源: https://codeday.me/bug/20191123/2065373.html