我在Google App Engine中使用python的requests库向专用服务器发送GET请求。当我提出要求我得到这样的警告:Google App Engine - SSL InsecurePlatformWarning
requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning
根据指向,我需要或者升级过去这GAE使用Python 2.7.x,或使用pyopenssl的documentation。由于我不相信我可以强制GAE使用Python 2.7.9,我试图使用pyopenssl。
按照页面上的指示,我已经下载了三个库建议到我的应用程序的lib目录中,并在那里我用我的请求尝试注入到pyopenssl与urllib3:
import requests.packages.urllib3.contrib.pyopenssl
requests.packages.urllib3.contrib.pyopenssl.inject_into_urllib3()
然而,这未能在devserver,并与下面的追溯生产服务器:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/s~servicey1564/1.383321878696068897/main.py", line 24, in <module>
from API import setupautomatorAPI
File "/base/data/home/apps/s~servicey1564/1.383321878696068897/API.py", line 12, in <module>
from ServiceActivationTest import uploadSAT, getSATsForService
File "/base/data/home/apps/s~servicey1564/1.383321878696068897/ServiceActivationTest/__init__.py", line 3, in <module>
from requests.packages.urllib3.contrib import pyopenssl as pyopenssl
File "/base/data/home/apps/s~servicey1564/1.383321878696068897/lib/requests/packages/__init__.py", line 95, in load_module
raise ImportError("No module named '%s'" % (name,))
ImportError: No module named 'requests.packages.urllib3.contrib.pyopenssl'
这import语句在Python解释器工作正常,如果我起飞结束的pyopenssl工作。 pyopenssl也是该路径中除__init__.py文件之外的第一个.py文件。
我在这里做错了什么?有没有更简单的方法来解决InsecurePlatformWarning?
更新:去插座API页面(谢谢shazow!)我发现我的问题的一部分是,httplib是行为不端,因为我缺乏一个环境变量。这并没有摆脱警告,但我的证书正在被接受!
嗯,我还没有完整的答案,但有一些提示:我不相信PyOpenSSL适用于AppEngine,因为它是一个编译模块。 AppEngine提供了它自己的版本。也许你需要启用'sockets' API来获得一个合适的SSLContext? https://cloud.google.com/appengine/docs/python/sockets/ – shazow 2015-04-02 17:04:34
我相信我已启用套接字。我的理解是,如果启用计费,套接字将自动可用。 – 2015-04-02 17:57:43