我一直在尝试访问APNS,以便向我开发的iOS应用发送推送通知。我已经创建了开发和生产证书请求,并在Apple开发中心签名:
对于每个证书(生产和开发),我有三个文件:
aps_development.cer: A
。cer`文件我在签署证书申请后已从Apple下载。dev.pem
:来自OSX钥匙串的.pem
公钥文件。dev.p12
:来自OSX钥匙串的.p12
私钥文件,带有密码(和dev_nopass.p12
:来自OSX钥匙串的.p12
私钥文件,带密码) 来自apns导入APN,Frame,Payload
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)
结果:
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
我尝试了p12
和p12_nopass
,生产和开发,并获得了相同的结果。
知道为什么我无法建立SSL连接以通过PyAPN发送推送通知吗?