使用Google App Engine和python请求在本地开发中支持HTTP连接隧道

使用Google App Engine和python请求在本地开发中支持HTTP连接隧道,python,google-app-engine,python-requests,Python,Google App Engine,Python Requests,GAE不支持HTTP连接隧道。这在生产服务器上是有意义的。然而,在本地我确实需要这个功能,因为我正在运行我自己的代理服务器(Squid3)来通过我学校的隧道。为了启用httpconnecttunnelling,我将gae的Python运行时中的httplib.py替换为默认的httplib,以便实现set\u tunnel。但这不适用于任何人。我得到了这个错误: Traceback (most recent call last): ... File "/path_to_my_projec

GAE不支持HTTP连接隧道。这在生产服务器上是有意义的。然而,在本地我确实需要这个功能,因为我正在运行我自己的代理服务器(Squid3)来通过我学校的隧道。为了启用
httpconnecttunnelling
,我将gae的Python运行时中的
httplib.py
替换为默认的
httplib
,以便实现
set\u tunnel
。但这不适用于任何人。我得到了这个错误:

Traceback (most recent call last):
  ...
  File "/path_to_my_project/requests/packages/urllib3/util.py", line 520, in resolve_cert_reqs
  res = getattr(ssl, 'CERT_' + candidate)
AttributeError: 'module' object has no attribute 'CERT_CERT_REQUIRED'
以下是产生错误的函数:

def resolve_cert_reqs(candidate):
    """ 
    Resolves the argument to a numeric constant, which can be passed to
    the wrap_socket function/method from the ssl module.
    Defaults to :data:`ssl.CERT_NONE`.
    If given a string it is assumed to be the name of the constant in the
    :mod:`ssl` module or its abbrevation.
    (So you can specify `REQUIRED` instead of `CERT_REQUIRED`.
    If it's neither `None` nor a string we assume it is already the numeric
    constant which can directly be passed to wrap_socket.
    """
    if candidate is None:
        return CERT_NONE

    if isinstance(candidate, str):
        res = getattr(ssl, candidate, None)
        if res is None:
            res = getattr(ssl, candidate)
        return res 

    return candidate
因此,我尝试检查
ssl
模块,结果如下:

{'__doc__': None, '__loader__': , '__name__': 'ssl', '__package__': None}
这很奇怪,因为普通的
ssl
模块看起来像这样

{'CERT_NONE': 0,
 'CERT_OPTIONAL': 1,
 'CERT_REQUIRED': 2,
 'DER_cert_to_PEM_cert': <function DER_cert_to_PEM_cert at 0x7f6df6ab4938>,
 'OPENSSL_VERSION': 'OpenSSL 1.0.1 14 Mar 2012',
 'OPENSSL_VERSION_INFO': (1, 0, 1, 0, 15),
 'OPENSSL_VERSION_NUMBER': 268439567L,
 'PEM_FOOTER': '-----END CERTIFICATE-----',
 'PEM_HEADER': '-----BEGIN CERTIFICATE-----',
 'PEM_cert_to_DER_cert': <function PEM_cert_to_DER_cert at 0x7f6df6ab49b0>,
 'PROTOCOL_SSLv23': 2,
 'PROTOCOL_SSLv3': 1,
 'PROTOCOL_TLSv1': 3,
 'RAND_add': <built-in function RAND_add>,
 'RAND_egd': <built-in function RAND_egd>,
 'RAND_status': <built-in function RAND_status>,
 'SSLError': <class 'ssl.SSLError'>,
 'SSLSocket': <class 'ssl.SSLSocket'>,
 'SSL_ERROR_EOF': 8,
 'SSL_ERROR_INVALID_ERROR_CODE': 9,
 'SSL_ERROR_SSL': 1,
 'SSL_ERROR_SYSCALL': 5,
 'SSL_ERROR_WANT_CONNECT': 7,
 'SSL_ERROR_WANT_READ': 2,
 'SSL_ERROR_WANT_WRITE': 3,
 'SSL_ERROR_WANT_X509_LOOKUP': 4,
 'SSL_ERROR_ZERO_RETURN': 6,
 '_DEFAULT_CIPHERS': 'DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2',
 '_PROTOCOL_NAMES': {1: 'SSLv3', 2: 'SSLv23', 3: 'TLSv1'},
 '_SSLv2_IF_EXISTS': None,
 ...
 }
此错误对应于
SSLSocket
类:

from socket import socket
class SSLSocket(socket):
   ...
所以我把它改成:

from _socket import socket
这会起作用,并导致下一个错误:

File "/path_to_gae/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1589, in LoadModuleRestricted
    description)
  File "/usr/lib/python2.7/dist-packages/httplib2/__init__.py", line 800, in <module>
    class HTTPSConnectionWithTimeout(httplib.HTTPSConnection):
AttributeError: 'module' object has no attribute 'HTTPSConnection'
这没有任何意义,因为我确实安装了
ssl.py


请帮忙!!!我将把我所有的名誉都献给能够帮助我运行这个程序的人。

首先,将
ssl.py
放到Python运行时中是行不通的
ssl.py
依赖于
\u ssl
模块,该模块在编译Python时实际上是一个C扩展构建,并针对OpenSSL进行链接。确保编译Python时使用SSL支持。另外值得注意的是,这就是请求不支持GAE的原因。它可能会工作,但可能不会。@Lukasa我确实删除了python并使用SSL支持重新编译了它。如果将
ssl.py
拖放到运行时中不起作用,您能推荐一些替代方法吗?不幸的是,Python中的ssl并不是很简单。我对任何事情都一无所知,尤其是如果你确实安装了OpenSSL进行编译的话。
File "/path_to_gae/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1589, in LoadModuleRestricted
    description)
  File "/usr/lib/python2.7/dist-packages/httplib2/__init__.py", line 800, in <module>
    class HTTPSConnectionWithTimeout(httplib.HTTPSConnection):
AttributeError: 'module' object has no attribute 'HTTPSConnection'
  File "/path_to_my_project/requests/adapters.py", line 363, in send
    raise SSLError(e)
SSLError: Can't connect to HTTPS URL because the SSL module is not available.