aisonet / google-api-python-client

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

HttpError.resp.reason always returns 'Ok' #193

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
http://code.google.com/p/google-api-python-client/source/browse/apiclient/errors
.py#46

self.resp.reason is always 'Ok'.

Even when one error occurs.

The 'reason' is not on self.resp.
It is on self.content which contains a json like this:
'{"error":{"errors":[{"domain":"global","reason":"userRateLimitExceeded","messag
e":"Quota Error: User Rate Limit Exceeded"}],"code":403,"message":"Quota Error: 
User Rate Limit Exceeded"}}'

Original issue reported on code.google.com by felippe....@gmail.com on 10 Sep 2012 at 9:56

GoogleCodeExporter commented 9 years ago
Seems the problem is on line 49. The correct line should be something like:
reason = data['error']['errors'][0]['reason']

The problem is that, I really don't know if the 'path' to 'reason' on the data 
dict will be always the same.

Original comment by felippe....@gmail.com on 10 Sep 2012 at 10:11

GoogleCodeExporter commented 9 years ago
You need to upgrade to httplib2 0.7.5, as this change addresses that issue:

 http://code.google.com/p/httplib2/source/detail?format=side&path=/python2/httplib2/__init__.py&r=fa8982bd19a2570da5e93dc424dbe49b037962d3&spec=svnfa8982bd19a2570da5e93dc424dbe49b037962d3

The dependencies for google-api-python-client should be updated to 0.7.5 to 
make sure everyone gets that fix. I will file a bug to that effect. Thanks!

Original comment by jcgregorio@google.com on 11 Sep 2012 at 1:49

GoogleCodeExporter commented 9 years ago
Hi Gregorio,
Thanks for your answer.
I tried upgrading to new httplib2 and still not working.
I'm trying to do something like 
https://developers.google.com/analytics/devguides/reporting/core/v3/coreErrors#b
ackoff
(take a look on the code for makeRequest()).
And as I said, it is not working.
My solution for now was to implement something like:
except HttpError, error:
 content = json.loads(error.content)
 reason = content.get('error').get('errors')[0].get('reason')
 reason in ['userRateLimitExceeded', 'quotaExceeded']:
        time.sleep((2 ** n) + (random.randint(0, 1000) / 1000))

Thank you.

Original comment by felippe....@gmail.com on 11 Sep 2012 at 6:09

GoogleCodeExporter commented 9 years ago
Please check the version of httplib2 you are running:

$ python
>>> import httplib2
>>> httplib2.__version__

should return 0.7.5 or later.

The code you pointed to in 

   http://code.google.com/p/google-api-python-client/source/browse/apiclient/errors.py#46

is just part of the definition of _get_reason() and is only called
from __repr__(), it has no effect on what error.resp.reason returns.

The value in error.resp.reason is the string part of the HTTP status
code, i.e. it's the 'Forbidden' part of '401 Forbidden'.

Your code looks good, but there could be more than one error so you
should loop over all the 'errors' and check the 'reason' in each one.

Original comment by jcgregorio@google.com on 11 Sep 2012 at 8:51