Dil*_*ine 32 python google-app-engine python-requests
我可以在Google App Engine上使用请求吗?我认为这个库非常适合创建REST客户端.
Eya*_*vin 41
安装requests-toolbelt
库:https:
//github.com/sigmavirus24/requests-toolbelt
对于App Engine,它可能是这样的: pip install requests-toolbelt -t lib
(参见:https://cloud.google.com/appengine/docs/python/tools/using-libraries-python-27#installing_a_library)
然后加:
from requests_toolbelt.adapters import appengine
appengine.monkeypatch()
Run Code Online (Sandbox Code Playgroud)
在你main.py
或同等中.
编辑:此解决方案现在是官方文档的一部分:https://cloud.google.com/appengine/docs/python/issue-requests#issuing_an_http_request
(在REQUESTS
标签中)
cat*_*cat 27
是.在谷歌的AppEngine(1.9.18版本)请求 版本2.3.0工程生产(但不是在SDK),如果你有计费启用,这使得插座的支持.
更新:截至2017年1月31日,Requests正在生产中,版本为2.9.1.但是,它不适用于Google Cloud SDK 141.0.0
Appengine SDK上的请求因所有https://请求而失败:
ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))
Run Code Online (Sandbox Code Playgroud)
请求版本2.4.1在生产中失败:
File "distlib/requests/adapters.py", line 407, in send
raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))
Run Code Online (Sandbox Code Playgroud)
请求版本2.5.1在生产中失败:
File "distlib/requests/adapters.py", line 415, in send
raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))
Run Code Online (Sandbox Code Playgroud)
请求版本2.3.0在生产中工作,但可能会导致Debian中的问题被删除SDK中的SSLv3支持(请求2.3.0带有它自己现在过时的urllib3).作为解决方法,可以在请求的urllib3副本的源中删除包含PROTOCOL_SSLv3的行.
'module' object has no attribute 'PROTOCOL_SSLv3'
Run Code Online (Sandbox Code Playgroud)
有关套接字支持的信息:https://cloud.google.com/appengine/docs/python/sockets/
现在这是可能的,我在appengine_config.py中使用这种变通办法的组合工作:
# Step 1: first add requests and requests-toolbelt to your requirements.txt (or however you install them via pip)
# Step 2: in appengine_config.py add the following snippet:
# see https://cloud.google.com/appengine/docs/python/issue-requests#issuing_an_http_request
import requests
import requests_toolbelt.adapters.appengine
# Use the App Engine Requests adapter. This makes sure that Requests uses
# URLFetch.
requests_toolbelt.adapters.appengine.monkeypatch()
# also monkey patch platform.platform() from https://code.google.com/p/googleappengine/issues/detail?id=12982
import platform
def patch(module):
def decorate(func):
setattr(module, func.func_name, func)
return func
return decorate
@patch(platform)
def platform():
return 'AppEngine'
Run Code Online (Sandbox Code Playgroud)