Getting ChunkedEncodingError: ('Connection broken: IncompleteRead

5.9k Views Asked by At

I am building an app for bigcommerce in python, using bigcommerce sdk (https://github.com/bigcommerce/bigcommerce-api-python) running on Google App Engine in when trying to fetch a tocken from bigcommerce getting following error:

  File "/base/data/home/apps/s~acp-bigcommerce/20161220t174745.397888154524804049/lib/bigcommerce/api.py", line 22, in oauth_fetch_token
    return self.connection.fetch_token(client_secret, code, context, scope, redirect_uri, token_url)
  File "/base/data/home/apps/s~acp-bigcommerce/20161220t174745.397888154524804049/lib/bigcommerce/connection.py", line 250, in fetch_token
    headers={'Content-Type': 'application/x-www-form-urlencoded'})
  File "/base/data/home/apps/s~acp-bigcommerce/20161220t174745.397888154524804049/lib/bigcommerce/connection.py", line 140, in post
    response = self._run_method('POST', url, data=data, headers=headers)
  File "/base/data/home/apps/s~acp-bigcommerce/20161220t174745.397888154524804049/lib/bigcommerce/connection.py", line 72, in _run_method
    return self._session.request(method, url, data=data, timeout=self.timeout, headers=headers)
  File "/base/data/home/apps/s~acp-bigcommerce/20161220t174745.397888154524804049/lib/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/base/data/home/apps/s~acp-bigcommerce/20161220t174745.397888154524804049/lib/requests/sessions.py", line 641, in send
    r.content
  File "/base/data/home/apps/s~acp-bigcommerce/20161220t174745.397888154524804049/lib/requests/models.py", line 781, in content
    self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
  File "/base/data/home/apps/s~acp-bigcommerce/20161220t174745.397888154524804049/lib/requests/models.py", line 706, in generate
    raise ChunkedEncodingError(e)
ChunkedEncodingError: ('Connection broken: IncompleteRead(108 bytes read)', IncompleteRead(108 bytes read))
2

There are 2 best solutions below

1
On

Finally found it: It appears that requests does not work on app engine so well, but there is a fix: https://github.com/kennethreitz/requests/compare/master...agfor:master

and this is where i took it from

https://github.com/wooyek/flask-social-blueprint/issues/18

1
On

If you're using requests in Google App Engine, it's recommended you use requests_toolbelt aswell.

You can read more about it here.

In your code, just use

from requests_toolbelt.adapters import appengine
appengine.monkeypatch()