iterative / PyDrive2

Google Drive API Python wrapper library. Maintained fork of PyDrive.
https://docs.iterative.ai/PyDrive2
Other
580 stars 69 forks source link

Google sometimes returns HTML error data instead of JSON data #251

Closed stevobailey closed 1 year ago

stevobailey commented 1 year ago

https://github.com/iterative/PyDrive2/blob/12ee0a7732c913f8e7e612ede7c6e2d338660da8/pydrive2/files.py#L31

I hit an HTTP error that reached here. I then received an HTML response instead of a JSON response, which caused an exception on this line. The exception:

  File "/usr/local/lib/python3.10/dist-packages/pydrive2/files.py", line 508, in Upload
    self._FilesUpdate(param=param)
  File "/usr/local/lib/python3.10/dist-packages/pydrive2/auth.py", line 84, in _decorated
    return decoratee(self, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/pydrive2/files.py", line 784, in _FilesUpdate
    raise ApiRequestError(error)
  File "/usr/local/lib/python3.10/dist-packages/pydrive2/files.py", line 31, in __init__
    content = json.loads(http_error.content.decode("utf-8"))
  File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The HTML response:

<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><title>Sorry...</title><style> body { font-family: verdana, arial, sans-serif; background-color: #fff; color: #000; }</style></head><body><div><table><tr><td><b><font face=sans-serif size=10><font color=#4285f4>G</font><font color=#ea4335>o</font><font color=#fbbc05>o</font><font color=#4285f4>g</font><font color=#34a853>l</font><font color=#ea4335>e</font></font></b></td><td style="text-align: left; vertical-align: bottom; padding-bottom: 15px; width: 50%"><div style="border-bottom: 1px solid #dfdfdf;">Sorry...</div></td></tr></table></div><div style="margin-left: 4em;"><h1>We're sorry...</h1><p>... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now.</p></div><div style="margin-left: 4em;">See <a href="https://support.google.com/websearch/answer/86640">Google Help</a> for more information.<br/><br/></div><div style="text-align: center; border-top: 1px solid #dfdfdf;"><a href="https://www.google.com">Google Home</a></div></body></html>

image

I'm guessing Google changed their response format.

shcheklein commented 1 year ago

I think it means that Google blocked the network or IP and request is not getting even to their internal servers, it's being caught somewhere before. I'm not sure we can do anything here tbh.