0

我正在尝试使用Hyper在我的 Python REST 服务器上实现 APNS 服务。由于 APNS 现在需要 HTTP/2 (ALPN) 协议,因此我无法get_response()从 Hyper 连接。它引发以下错误。

Traceback (most recent call last):
  File "/usr/lib64/python3.5/dist-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/lib64/python3.5/dist-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/lib64/python3.5/dist-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib64/python3.5/dist-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/lib64/python3.5/dist-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/lib/python3.5/dist-packages/rest_framework/views.py", line 489, in dispatch
    response = self.handle_exception(exc)
  File "/usr/lib/python3.5/dist-packages/rest_framework/views.py", line 449, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/lib/python3.5/dist-packages/rest_framework/views.py", line 486, in dispatch
    response = handler(request, *args, **kwargs)
  File "/usr/lib/python3.5/dist-packages/rest_framework/decorators.py", line 52, in handler
    return func(*args, **kwargs)
  File "/opt/vr-inspire/apns/views.py", line 137, in apns
    resp = conn.get_response()
  File "/usr/lib/python3.5/dist-packages/hyper/common/connection.py", line 129, in get_response
    return self._conn.get_response(*args, **kwargs)
  File "/usr/lib/python3.5/dist-packages/hyper/http11/connection.py", line 203, in get_response
    self._sock.fill()
  File "/usr/lib/python3.5/dist-packages/hyper/common/bufsocket.py", line 169, in fill
    raise ConnectionResetError()
ConnectionResetError

我做了一些研究,结果发现 ALPN 需要 OpenSSL 1.0.2。我参考这篇文章从源代码编译了 OpenSSL 1.0.2i 和 Python 3.5.1。

我检查了 ssl 版本import ssl print(ssl.OPENSSL_VERSION)并返回OpenSSL 1.0.2i 22 Sep 2016。但ssl.HAS_ALPN返回False

我正在使用 Amazon Linux,如何使用 ALPN 向 APNS 服务器发送请求?谢谢你。

4

1 回答 1

0

我尝试将 python 3.6.1 与 openssl 1.0.2k 一起使用,它可以工作。

于 2017-09-25T05:07:16.240 回答