Using the Requests python library in Google App Engine

前端 未结 3 1704
执念已碎
执念已碎 2020-12-08 07:37

I\'m trying to use the awesome Requests library on Google App Engine. I found a patch for urllib3, which requests relies on, that is compatible with App Engine. https://gith

相关标签:
3条回答
  • 2020-12-08 08:06

    As mentioned, master branch of standalone urllib3 supposedly supports AppEngine now (I'll do a proper PyPI release once someone confirms this fact), but Requests does not yet support AppEngine since it makes assumption about various filesystem things to load configuration files which don't exist on AppEngine. Specifically the error you ran into has to do with loading the ~/.netrc configuration file.

    See Issue #493.

    For what it's worth, the equivalent in urllib3 would be:

    import urllib3
    http = urllib3.PoolManager()
    response = http.request('GET', 'someurl')
    

    Update: urllib3 v1.3 was released yesterday which includes AppEngine support.

    0 讨论(0)
  • 2020-12-08 08:06

    On Google Appengine (version 1.9.18) requests version 2.3.0 (only!) works IN PRODUCTION (but not on SDK) if you have billing enabled, which enables sockets support.

    requests on the Appengine SDK fails with all https:// requests:

      ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))
    

    requests version 2.4.1 fails with:

      File "distlib/requests/adapters.py", line 407, in send
        raise ConnectionError(err, request=request)
      ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))
    

    requests version 2.5.1 fails with:

      File "distlib/requests/adapters.py", line 415, in send
        raise ConnectionError(err, request=request)
      ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))
    

    Info on sockets support: https://cloud.google.com/appengine/docs/python/sockets/

    PS: Replace awsome with very-painful if you intend to use requests on GAE.

    See Also: Can Python Requests library be used on Google App Engine?

    0 讨论(0)
  • 2020-12-08 08:29

    You can use the latest version of Requests on Google App Engine with the help of requests-toolbelt. This configures Requests to use urllib3's underlying support for App Engine's URLFetch service.

    • Google's documentation on how to use Requests.
    • Straightforward sample of using Requests on Google App Engine.
    • request-toolbelt's AppEngineAdapter.
    • urllib3's AppEngineManager.
    0 讨论(0)
提交回复
热议问题