Issue 304 in google-api-python-client: BadStatusLine raised on a request (+headers) that works elsewhere.

234 views
Skip to first unread message

google-api-p...@googlecode.com

unread,
Oct 3, 2013, 10:42:05 AM10/3/13
to google-api-p...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 304 by rossdjo...@gmail.com: BadStatusLine raised on a request
(+headers) that works elsewhere.
http://code.google.com/p/google-api-python-client/issues/detail?id=304

Calling the Google Analytics Data API, our code makes three main requests
for three different pagePaths. The first and third calls complete
successfully but the second fails with a BadStatusLine on every run.

I've turned on logging and it tells me:

send: 'GET
/analytics/v3/data/ga?sort=-ga%3Apageviews&max-results=100000&dimensions=ga%3ApagePath&start-date=2013-10-01&ids=ga%3A21906051&metrics=ga%3Apageviews%2Cga%3Avisits&filters=ga%3ApagePath%3D%7E%2Fdata.gov.uk%2Fpublisher%2F%5Ba-z0-9%5C-_%5D%2B%24&alt=json&end-date=2013-10-03
HTTP/1.1\r\nHost: www.googleapis.com\r\ncontent-length: 0\r\nauthorization:
Bearer ya29.REST_OF_TOKEN\r\naccept-encoding: gzip, deflate\r\naccept:
application/json\r\nuser-agent: google-api-python-client/1.2 (gzip)\r\n\r\n'
reply: ''

So understandable that it got a BadStatusLine with an empty response.
However I translated that call into the following curl request which
completes successfully and shows the data I would expect.

curl -H "content-length: 0" -H "accept: application/json"
-H "accept-encoding: gzip, deflate" -H "user-agent:
google-api-python-client/1.2 (gzip)" -H "Authorization: Bearer
ya29.REST_OF_TOKEN" "https://www.googleapis.com/analytics/v3/data/ga?sort=-ga%3Apageviews&max-results=100000&dimensions=ga%3ApagePath&start-date=2013-10-01&ids=ga%3A21906051&metrics=ga%3Apageviews%2Cga%3Avisits&filters=ga%3ApagePath%3D%7E%2Fdata.gov.uk%2Fpublisher%2F%5Ba-z0-9-_%5D%2B%24&alt=json&end-date=2013-10-03"

I also get a valid response when I do the following in the repl:

>>> import requests
>>> headers['authorization'] = "Bearer ya29.REST_OF_TOKEN"
>>> r =
>>> requests.get("https://www.googleapis.com/analytics/v3/data/ga?sort=-ga%3Apageviews&max-results=100000&dimensions=ga%3ApagePath&start-date=2013-10-01&ids=ga%3A21906051&metrics=ga%3Apageviews%2Cga%3Avisits&filters=ga%3ApagePath%3D%7E%2Fdata.gov.uk%2Fpublisher%2F%5Ba-z0-9-_%5D%2B%24&alt=json&end-date=2013-10-03",
>>> headers=headers)
>>> r
<Response [200]>





--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

google-api-p...@googlecode.com

unread,
Nov 14, 2013, 9:09:36 AM11/14/13
to google-api-p...@googlegroups.com

Comment #1 on issue 304 by myself...@gmail.com: BadStatusLine raised on
I will also get this error periodically with the Drive API. It will
sporadically happen, but otherwise not happen most of the time. It's as if
there's a malformed response. I'll either do the same operation again, or
remount, and it'll be fine.

ERROR Could not send delete for entry with ID
[0B2iR2qHm9cDTdWstXzczV2NNdGs].#012
Traceback (most recent call last):

File "/usr/local/lib/python2.7/dist-packages/gdrivefs-0.13.4-py2.7.egg/gdrivefs/gdtool/drive.py",
line 685, in remove_entry
result = client.files().delete(args).execute()

File "/usr/local/lib/python2.7/dist-packages/google_api_python_client-1.2-py2.7.egg/oauth2client/util.py",
line 132, in positional_wrapper
return wrapped(args, *kwargs)
File "/usr/l
ocal/lib/python2.7/dist-packages/google_api_python_client-1.2-py2.7.egg/apiclient/http.py",
line 716, in execute
body=self.body, headers=self.headers)

File "/usr/local/lib/python2.7/dist-packages/google_api_python_client-1.2-py2.7.egg/oauth2client/util.py",
line 132, in positional_wrapper
return wrapped(args, *kwargs)

File "/usr/local/lib/python2.7/dist-packages/google_api_python_client-1.2-py2.7.egg/oauth2client/client.py",
line 490, in new_request
redirections, connection_type)
File "/usr/local/lib/pytho
n2.7/dist-packages/httplib2-0.8-py2.7.egg/httplib2/init.py", line 1570, in
request
(response, content) = self.request(conn, authority, uri, requesturi,
method, body, headers, redirections, cachekey)

File "/usr/local/lib/python2.7/dist-packages/httplib2-0.8-py2.7.egg/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-0.8-py2.7.egg/httplib2/init.py",
line 1286, in connrequest
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.readstatus()
File "/usr/lib/python2.7/httplib.py", line 371, in readstatus
raise BadStatusLine(line)

BadStatusLine: ''

Very annoying.

google-api-p...@googlecode.com

unread,
Nov 14, 2013, 9:12:21 AM11/14/13
to google-api-p...@googlegroups.com

Comment #2 on issue 304 by myself...@gmail.com: BadStatusLine raised on
Also, after reading this SO post, there's a chance that the token expires
mid-operation:
http://stackoverflow.com/questions/17180433/google-mirror-api-throwing-badstatusline-exception-python .
In their case, it's a very-long upload. Theoretically, though, it could
occur during a short operation.

google-api-p...@googlecode.com

unread,
Nov 14, 2013, 9:26:23 AM11/14/13
to google-api-p...@googlegroups.com

Comment #3 on issue 304 by rossdjo...@gmail.com: BadStatusLine raised on a
Eventually I switched to only using the google-api lib to process the
refresh token (before each request, I only make 3 a day), and make the http
requests myself with python-request
(https://github.com/datagovuk/ckanext-ga-report/blob/master/ckanext/ga_report/download_analytics.py#L251-L280) ,
and I've not had a problem since. No idea if it is related or not.

BadStatusLine gets thrown when the server returns nothing, not even an
error response code, and so I imagine that somewhere on the analytics
back-end it is failing to provide any response at all. Whatever the reason,
I'm not sure this is a 'working as intended' ;) A 502, or 504 would be
nicer.

google-api-p...@googlecode.com

unread,
Oct 12, 2014, 8:37:36 PM10/12/14
to google-api-p...@googlegroups.com

Comment #4 on issue 304 by Dan.r.sc...@gmail.com: BadStatusLine raised on a
request (+headers) that works elsewhere.
https://code.google.com/p/google-api-python-client/issues/detail?id=304

Yeah I have the same problem. I have had some success by just trying
twice, but even them it doesn't really work:

try:
return request.execute()
except httplib.BadStatusLine as e:
print e.line, e.message
print '[GOOGLE_CALENDAR]: Got BadStatusLine. Retrying...'
try:
return request.execute()
except httplib.BadStatusLine as e:
print '[GOOGLE_CALENDAR]: Got BadStatusLine again! Raising.'
raise
Reply all
Reply to author
Forward
0 new messages