Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid JSON being logged for no good reason #1116

Closed
kapilt opened this issue Dec 1, 2020 · 0 comments · Fixed by #1117
Closed

Invalid JSON being logged for no good reason #1116

kapilt opened this issue Dec 1, 2020 · 0 comments · Fixed by #1117
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@kapilt
Copy link
Contributor

kapilt commented Dec 1, 2020

Environment details

  • OS: Linux
  • Python: 3.9
  • api client Version: 1.12.8
    • OS type and version:
    • Python version: python --version
    • pip version: pip --version
    • google-api-python-client version: pip show google-api-python-client

Steps to reproduce

  1. use google api client against a service thats not been enabled in a project, watch it throw an invalid message
2020-12-01 11:35:58,296: googleapiclient.http:WARNING Invalid JSON content from response: b'{\n  "error": {\n    "code": 403,\n    "message": "Cloud Functions API has not been used in project 683429142524 before 
or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudfunctions.googleapis.com/overview?project=683429142524 then retry. If you enabled this API recently, wait a few minutes
 for the action to propagate to our systems and retry.",\n    "status": "PERMISSION_DENIED",\n    "details": [\n      {\n        "@type": "type.googleapis.com/google.rpc.Help",\n        "links": [\n          {\n 
           "description": "Google developers console API activation",\n            "url": "https://console.developers.google.com/apis/api/cloudfunctions.googleapis.com/overview?project=683429142524"\n          }\
n        ]\n      },\n      {\n        "@type": "type.googleapis.com/google.rpc.ErrorInfo",\n        "reason": "SERVICE_DISABLED",\n        "domain": "googleapis.com",\n        "metadata": {\n          "service":
 "cloudfunctions.googleapis.com",\n          "consumer": "projects/683429142524"\n        }\n      }\n    ]\n  }\n}\n'     

Solution

Either stop error sniffing or expand it to additional valid use scenarios, in this case the particular payload was

{'error': {'code': 403,                                                                                                                                                                                             
           'details': [{'@type': 'type.googleapis.com/google.rpc.Help',                                                                                                                                             
                        'links': [{'description': 'Google developers console '                                                                                                                                      
                                                  'API activation',                                                                                                                                                 
                                   'url': 'https://console.developers.google.com/apis/api/cloudfunctions.googleapis.com/overview?project=926761696986'}]},                                                          
                       {'@type': 'type.googleapis.com/google.rpc.ErrorInfo',                                                                                                                                        
                        'domain': 'googleapis.com',                                                                                                                                                                 
                        'metadata': {'consumer': 'projects/redacted',                                                                                                                                           
                                     'service': 'cloudfunctions.googleapis.com'},                                                                                                                                   
                        'reason': 'SERVICE_DISABLED'}],                                                                                                                                                             
           'message': 'Cloud Functions API has not been used in project '                                                                                                                                           
                      '926761696986 before or it is disabled. Enable it by '                                                                                                                                        
                      'visiting '                                                                                                                                                                                   
                      'https://console.developers.google.com/apis/api/cloudfunctions.googleapis.com/overview?project=redacted '                                                                                 
                      'then retry. If you enabled this API recently, wait a '                                                                                                                                       
                      'few minutes for the action to propagate to our systems '                                                                                                                                     
                      'and retry.',                                                                                                                                                                                 
           'status': 'PERMISSION_DENIED'}}       

there's a bunch of well known key sniffing in http.py on error which doesn't properly look at message or status and should be updated to do the same to avoid throwing an Invalid JSON message on perfectly valid json.

kapilt added a commit to kapilt/google-api-python-client that referenced this issue Dec 1, 2020
kapilt added a commit to kapilt/google-api-python-client that referenced this issue Dec 1, 2020
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Dec 2, 2020
@parthea parthea added the type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. label Dec 2, 2020
@parthea parthea self-assigned this Dec 2, 2020
@parthea parthea added priority: p2 Moderately-important priority. Fix may not be included in next release. and removed triage me I really want to be triaged. labels Dec 2, 2020
gcf-merge-on-green bot pushed a commit that referenced this issue Dec 2, 2020
Fixes #1116 🦕

Don't throw invalid JSON messages for valid JSON.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants