When using the Mirror API, I randomly get a "BadStatusLine" exception from several API calls, including timeline().insert
and timeline.list
. From trolling around SO for simliar problems in python, I suspect this is some kind of malformed response from the server.
It seems to happen randomly and possibly after a period of not using the API. Here's a sample stack trace:
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: ''
This code works most of the time, but every once in a while I get a response like this.
Update: My code was creating the Google API classes and using them for the duration of the service. Once it got time to renew my oauth2
token (1 hour) I'd get this error once or twice then it would start working again. I was able to refactor my code so it creates the API classes on each request and the problem has gone away. This appears to be a known bug in Google's API, see the selected answer from Anthony Tuininga for more information.
This problem appears to be a known issue. I have experienced it myself consistently. If a single file takes more than 1 hour to upload, then this error occurs. If a different file is uploaded the API refreshes the token properly. See this bug for more information. It is apparently not fixed yet and there is no ETA on when it will be fixed. :-(
https://code.google.com/p/google-api-python-client/issues/detail?id=231