使用Mirror API时,我会从几个API调用中随机获取“BadStatusLine”异常,包括timeline().insert
和timeline.list
。为了解决python中的simliar问题,我想知道这是来自服务器的某种格式错误的响应。
它似乎是随机发生的,可能是在一段时间没有使用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。 :-(
https://code.google.com/p/google-api-python-client/issues/detail?id=231
状态行是HTTP响应返回的第一行。它包含状态代码,如200,404,500等。如果httplib无法读取状态行,则无法读取有关它的任何信息。
问题通常是由错误的HTTP请求或服务器问题引起的。尝试从浏览器发出请求以查看它向您显示的内容。或者,您可以使用curl
或wget
提出请求。
您的堆栈跟踪显示oauth2client
,因此您必须尝试OAuth 2协议。也许之前的请求导致了错误,而这只是在服务器上遇到了一个关闭的门。记录所有请求和响应可以帮助您查看导致故障的原因。