Python PyAPNs抛出设备不支持的IOError操作

Python PyAPNs抛出设备不支持的IOError操作,python,ios,apple-push-notifications,pyapns,Python,Ios,Apple Push Notifications,Pyapns,我正试图在本教程中为我的iOS推送应用程序实现APNS 根据描述,我什么都做了。 运行此命令后 openssl s_client-connect gateway.sandbox.push.apple.com:2195-cert-PushChatCert.pem-key-PushChatKey.pem 我收到一条大消息,表明一切都按预期进行了连接 我现在有两个文件PushChatCert.pem和PushChatKey.pem 和token\u hex='xxxxxxxxxxxxxxxxxxxxx

我正试图在本教程中为我的iOS推送应用程序实现
APNS

根据描述,我什么都做了。 运行此命令后
openssl s_client-connect gateway.sandbox.push.apple.com:2195-cert-PushChatCert.pem-key-PushChatKey.pem

我收到一条大消息,表明一切都按预期进行了连接

我现在有两个文件
PushChatCert.pem
PushChatKey.pem
token\u hex='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

因此,对于从服务器发送推送通知,我将遵循以下步骤

在我的python shell中完成所有这些操作后,它将抛出设备不支持的
IOError:[Errno 19]操作

import time
from apns import APNs, Frame, Payload
apns = APNs(use_sandbox=True, cert_file='PushChatCert.pem', key_file='PushChatKey.pem')

# Send a notification
token_hex = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
payload = Payload(alert="Hello World!", sound="default", badge=1)
apns.gateway_server.send_notification(token_hex, payload)
错误
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
apns.网关\服务器。发送\通知(令牌\十六进制,有效负载)
文件“/Library/Python/2.7/site packages/apns.py”,第544行,在发送通知中
self.write(self.\u get\u通知(令牌\u十六进制,有效负载))
文件“/Library/Python/2.7/site packages/apns.py”,第273行,以书面形式
返回self.\u connection().write(字符串)
文件“/Library/Python/2.7/site packages/apns.py”,第254行,在_连接中
self._connect()
文件“/Library/Python/2.7/site packages/apns.py”,第230行,in\u connect
self.\u ssl=wrap\u套接字(self.\u套接字、self.key\u文件、self.cert\u文件)
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py”,第891行,位于wrap_套接字中
密码=密码)
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py”,第509行,在__
self.\u context.load\u cert\u chain(certfile,keyfile)
IOError:[Errno 19]设备不支持操作
编辑: 在我的终端中运行此评论之后
openssl s_client-connectgateway.sandbox.push.apple.com:2195-cert-PushChatCert.pem-key-PushChatKey.pem

depth=1/C=US/O=trust,Inc./OU=www.trust.net/rpa通过引用合并/OU=(C)2009 trust,Inc./CN=委托认证机构-L1C
验证错误:num=20:无法获取本地颁发者证书

因此,我下载了
trust_2048_ca.cer
文件并保存在同一文件夹中,然后从我运行的终端下载

openssl s_client-connect-gateway.sandbox.push.apple.com:2195-CAfile-estrust\u 2048\u ca.cer-cert-PushChatCert.pem-key-PushChatKey.pem

openssl pkcs12 -in apns-dev-cert.p12 -out apns_development.pem -nodes -clcerts

那么这个问题已经解决了,但是如何在
PyAPNs
中执行呢?

问题已经解决了。由于python无法从该文件目录访问文件,因此出现了一些SSL安全问题

我正在学习这个教程。 如本教程所述,在创建了
aps\u development.cer
文件之后,我这样做是为了得到.pem文件

$ openssl x509 -in aps_development.cer -inform der -out PushChatCert.pem

Convert the private key’s .p12 file into a .pem file:

$ openssl pkcs12 -nocerts -out PushChatKey.pem -in PushChatKey.p12
Enter Import Password: 
MAC verified OK
Enter PEM pass phrase: 
Verifying - Enter PEM pass phrase:
在完成了所有我拥有的
PushChatKey.pem
PushChatCert.pem
文件后,我无法向我的设备发送推送通知

我是怎么解决的? 最后,我从一开始就尝试创建这些证书,但这次是在其他教程之后

创建名为
aps\u developer\u identity.cer下载的SSL证书后。双击它,将其安装到Keychain Access应用程序中。您的提供商应用程序将使用SSL证书,以便它可以联系APN向您的应用程序发送推送通知

从本地Mac和“登录”密钥链启动密钥链助手,按“证书”类别进行筛选。您将看到一个名为“Apple Development iOS推送服务”的可扩展选项:

展开此选项,然后右键单击“Apple Development iOS推送服务”->导出“Apple Development iOS推送服务…”。将此文件另存为
apns-dev-cert.p12
文件,您可以访问它

现在从
apns-dev-cert.p12
使用终端上的这些命令生成.pem

openssl pkcs12 -in apns-dev-cert.p12 -out apns.crt.pem -clcerts -nokeys
openssl pkcs12 -in apns-dev-cert.p12 -out apns.key.pem -nocerts -nodes
如果要创建
single.pem

openssl pkcs12 -in apns-dev-cert.p12 -out apns_development.pem -nodes -clcerts
现在将这些
apns.crt.pem
apns.key.pem
文件与一起使用,它就像魔术一样工作

仔细创建您的
供应档案

谢谢

openssl pkcs12 -in apns-dev-cert.p12 -out apns_development.pem -nodes -clcerts