1ap / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
0 stars 0 forks source link

BadStatusLine Exception thrown - how to handle to continue? #333

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hello,

I get a more than the occasional BadStatusLine Exception, I came across what 
might be a similar problem using the v2 API whilst implementing an API in Perl 
it turned out to be lots of redirects.

Have you any advice on how I could resolve these? Placing the call in a while 
loop (checking for non existence of the BadStatusLine Exception has the 
potential to generate an infinite loop) The error seems to be caused by 
libraries - hence my reluctance to fiddle with those

to reproduce the problem:

storage = file.Storage(self.storage_file)
credentials = storage.get()
if credentials is None or credentials.invalid:
  credentials = tools.run_flow(FLOW, storage, flags)
    # Create an httplib2.Http object to handle our HTTP requests and authorize it
    # with our good Credentials.
http = httplib2.Http()
http = credentials.authorize(http)
    # Construct the service object for the interacting with the Calendar API.
self.service=discovery.build('calendar', 'v3', http=http)

fmt = '%Y-%m-%dT%H:%M:%S%z'
startdate=<add here ??>
enddate=<add here ??>

self.service.events().list(calendarId=somecalid,  singleEvents='True', 
timeMin=startdate.strftime(fmt),timeMax=enddate.strftime(fmt), 
pageToken=page_token).execute()

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

Python 2.7.8 (default, Jul  3 2014, 09:25:32)
Linux hel 2.6.32-358.11.1.el6.x86_64 #1 SMP Wed Jun 12 03:34:52 UTC 2013 x86_64 
x86_64 x86_64 GNU/Linux

not sure how to get version of apiclient, httplib2 & oauth2client

(        easy_install --upgrade google-api-python-client )

Please provide any additional information below.

results in exception being thrown

  File "sample.py", line 228, in add_event
    events = self.service.events().list(calendarId=mycal['id'],  singleEvents='True', timeMin=startdate.strftime(fmt),timeMax=enddate.strftime(fmt), pageToken=page_token).execute()
  File "/home/sms67/fileserv/hel/Src_svn/apps/GoogleCalSync/scripts/oauth2client/util.py", line 132, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/sms67/fileserv/hel/Src_svn/apps/GoogleCalSync/scripts/apiclient/http.py", line 716, in execute
    body=self.body, headers=self.headers)
  File "/home/sms67/fileserv/hel/Src_svn/apps/GoogleCalSync/scripts/oauth2client/util.py", line 132, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/sms67/fileserv/hel/Src_svn/apps/GoogleCalSync/scripts/oauth2client/client.py", line 490, in new_request
    redirections, connection_type)
  File "/home/sms67/fileserv/hel/Src_svn/apps/GoogleCalSync/scripts/httplib2/__init__.py", line 1570, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/home/sms67/fileserv/hel/Src_svn/apps/GoogleCalSync/scripts/httplib2/__init__.py", line 1317, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/home/sms67/fileserv/hel/Src_svn/apps/GoogleCalSync/scripts/httplib2/__init__.py", line 1286, in _conn_request
    response = conn.getresponse()
  File "/home/sms67/fileserv/hel/Src_svn/apps/GoogleCalSync/python/lib/python2.7/httplib.py", line 1067, in getresponse
    response.begin()
  File "/home/sms67/fileserv/hel/Src_svn/apps/GoogleCalSync/python/lib/python2.7/httplib.py", line 409, in begin
    version, status, reason = self._read_status()
  File "/home/sms67/fileserv/hel/Src_svn/apps/GoogleCalSync/python/lib/python2.7/httplib.py", line 373, in _read_status
    raise BadStatusLine(line)
BadStatusLine: ''

Original issue reported on code.google.com by stephen....@gmail.com on 14 Aug 2014 at 12:26