我在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