简体   繁体   English

使用PyAPNS发送推送消息时出现ssl.SSLError

[英]ssl.SSLError when sending Push message using PyAPNS

I've been trying to access the APNS in order to send push notifications to an iOS app I develop. 我一直在尝试访问APNS,以便向我开发的iOS应用发送推送通知。 I have created a development and production certificate requests and signed them on the Apple dev center: 我创建了开发和生产证书申请,并在Apple开发中心上签名了:

My certificates 我的证书

在此处输入图片说明

For each certificate (production and development), I have three files: 对于每个证书(生产和开发),我都有三个文件:

  1. aps_development.cer: A .cer` file I have downloaded from Apple after signing the certificate request. aps_development.cer: A我在签署证书申请后从Apple下载了aps_development.cer: A .cer`文件。
  2. dev.pem : A .pem public key file from the OSX keychain. dev.pem :OSX钥匙串中的.pem公钥文件。
  3. dev.p12 : A .p12 private key file from the OSX keychain, with password (and dev_nopass.p12 : A .p12 private key file from the OSX keychain, with password). dev.p12 :来自OSX钥匙串的.p12私钥文件,带有密码(而dev_nopass.p12 :来自OSX钥匙串的.p12私钥文件,带有密码)。

What I've tried 我尝试过的

  1. Cloned and installed PyAPNs form github (The PyPi version seems a bit old and causes import errors.). 从github克隆并安装了PyAPNs (PyPi版本似乎有点旧,并导致导入错误。)。
  2. Adapted the example code to: 将示例代码修改为:

from apns import APNs, Frame, Payload 从apns导入apns,框架,有效载荷

p12 = '/path/to/dev.p12'
p12_nopass = '/path/to/dev_nopass.p12'
pem = '/path/to/dev.pem'
cer = '/path/to/aps_development.cer'

apns = APNs(use_sandbox=True,
            cert_file=pem,
            key_file=p12_nopass)

# Send a notification
# Dummy token, but it does not cause the error (SSL fails before token check)
token_hex = 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b87'
payload = Payload(alert="Hello World!", sound="default", badge=1)
apns.gateway_server.send_notification(token_hex, payload)

Result: 结果:

Traceback (most recent call last):
  File "apple_push_driver.py", line 18, in <module>
    apns.gateway_server.send_notification(token_hex, payload)
  File "/path_to/site-packages/apns.py", line 381, in send_notification
    self.write(self._get_notification(token_hex, payload))
  File "/path_to/apns.py", line 174, in write
    return self._connection().write(string)
  File "/path_to/apns.py", line 167, in _connection
    self._connect()
  File "/path_to/apns.py", line 151, in _connect
    self._ssl = wrap_socket(self._socket, self.key_file, self.cert_file)
  File "/path_to/ssl.py", line 387, in wrap_socket
    ciphers=ciphers)
  File "/path_to/ssl.py", line 141, in __init__
    ciphers)
ssl.SSLError: [Errno 336265225] _ssl.c:351: error:140B0009:SSL routines:SSL_CTX_use_PrivateKey_file:PEM lib

I tried both p12 and p12_nopass , production and dev, and got the same results. 我同时尝试了p12p12_nopass ,production和dev,并获得了相同的结果。

Any idea why I can't make SSL connection in order to send a Push notification via PyAPNs? 知道为什么我无法建立SSL连接才能通过PyAPN发送推送通知吗?

The problem was using the original .p12 / cer . 问题是使用原始的.p12 / cer files. 文件。 They should be converted to pem file, using the fine instructions here . 应使用此处的详细说明将它们转换为pem文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 urllib3 时 ssl.SSLError - ssl.SSLError when using urllib3 ssl.SSLError: ('No cipher can be selected') 当试图在 Python ZEA52C36203C5F99C3CE2ZZ442D531B1A2 中设置 TLS1.3 密码套件时 - ssl.SSLError: ('No cipher can be selected') When Trying to Set TLS1.3 Cipher Suites in Python SSL 尝试处理HTTPS请求Web服务器时出现“ ssl.SSLError:…无共享密码” - “ssl.SSLError: … No shared cipher” when trying to handle HTTPS requests webserver 使用 Ubuntu 20.4 和 Python Imaplib:我可以覆盖 ssl.SSLError:[SSL:DH_KEY_TO_OSMALL] - Using Ubuntu 20.4 & Python Imaplib: Can I override ssl.SSLError: [SSL: DH_KEY_TOO_SMALL]? ssl.SSLError:tlsv1 警报协议版本 - ssl.SSLError: tlsv1 alert protocol version 使用python和PyAPNS发送iOS推送通知 - Sending iOS push notifications with python and PyAPNS python ssl ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] 不支持的协议 (_ssl.c:590) - python ssl ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:590) Python ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:748) - Python ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748) Python中的Azure服务管理 - ssl.SSLError:[SSL] PEM lib(_ssl.c:2084) - Azure Service Management in Python - ssl.SSLError: [SSL] PEM lib (_ssl.c:2084) ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:852) - ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM