0

GAE 不支持HTTP CONNECT Tunnelling. 在生产服务器上是有意义的。但是,在本地我真的需要这个功能,因为我正在运行我自己的代理服务器(Squid3)来通过我学校的隧道。为了启用HTTP Connect Tunnelling,我将httplib.pygae 的 Python 运行时替换为默认值httplib,以便set_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,
 ...
 }

除其他事项外。所以我尝试加入一个本地版本,ssl.py因为显然 GAE 运行时没有提供这个模块并且能够继续......到下一个错误。

  File "/path_to_my_project/requests/packages/urllib3/ssl.py", line 139, in __init__
    ciphers)
TypeError: must be _socket.socket, not socket

此错误对应于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'

我再次谷歌,发现如果在 libssl-dev 之前安装了 python,这将不起作用。所以我重新编译了 Python 和所有这些,这让我遇到了下一个错误

  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.

这没有任何意义,因为我确实已经ssl.py安装了。

请帮忙!!!我会把我所有的声誉都献给能帮助我完成这项工作的人。

4

0 回答 0