【问题标题】:Why does using the Google APIs Python client in appengine with GAE_USE_SOCKETS_HTTPLIB result in ResponseNotReady为什么在带有 GAE_USE_SOCKETS_HTTPLIB 的 appengine 中使用 Google APIs Python 客户端会导致 ResponseNotReady
【发布时间】:2015-09-13 00:51:15
【问题描述】:

代码在 SDK 中可以正常工作,但在 Google AppEngine 上,它会爆炸:

  File "./oauth2client/util.py", line 137, in positional_wrapper
  File "./googleapiclient/discovery.py", line 197, in build
  File "./oauth2client/util.py", line 137, in positional_wrapper
  File "./oauth2client/client.py", line 563, in new_request
  File "./httplib2/__init__.py", line 1608, in request
  File "./httplib2/__init__.py", line 1350, in _request
  File "./httplib2/__init__.py", line 1306, in _conn_request
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/python_std_lib/httplib.py", line 1033, in getresponse
    raise ResponseNotReady()
ResponseNotReady

这仅在 GAE_USE_SOCKETS_HTTPLIB 开启时发生。

【问题讨论】:

    标签: google-app-engine google-api google-api-python-client


    【解决方案1】:

    出现这种情况是因为 Google API 库没有意识到这一点,并且盲目地使用套接字连接到 https://www.googleapis.com,这是不允许的。此外,实际代码隐藏了真正的错误,即在尝试创建套接字时权限被拒绝。

    我不知道有任何解决方法,除了禁用 httplib 的套接字,或者不使用提供的库,而是使用基于请求的库并为这些域安装使用 urlfetch 的适配器。

    【讨论】:

      【解决方案2】:

      套接字连接仅适用于付费应用。您是否为您的应用设置了计费?

      来自documentation on sockets

      套接字仅适用于付费应用,来自套接字的流量按传出带宽计费。

      你为什么还要尝试使用套接字?

      【讨论】:

      • 因为我需要上传和下载超过10MiB。是的。它是一个付费应用程序,从更往下看:私有、广播、多播和 Google IP 范围被阻止。
      【解决方案3】:

      除了@gcbirzan 的回答。以下是使其工作的步骤:-

      • 评论GAE_USE_SOCKETS_HTTPLIB: True 如果它设置在app.yamlenv_variables
      • 对于使用 pip install -t lib/ requests_toolbelt 安装 requests_toolbelt 的请求(请确保您的请求版本 >= 2.10.0 才能正常工作)
      • main.py 中包含以下行以启用 requests_toolbelt 适配器
        import requests_toolbelt.adapters.appengine requests_toolbelt.adapters.appengine.monkeypatch()

      以上步骤应该足以解决这个问题。

      【讨论】:

        猜你喜欢
        • 2011-06-21
        • 2014-04-23
        • 2021-04-11
        • 2013-01-25
        • 1970-01-01
        • 1970-01-01
        • 2016-06-13
        • 2017-01-01
        • 1970-01-01
        相关资源
        最近更新 更多