Python Django推送通知-Can';无法读取ANPS证书文件

Python Django推送通知-Can';无法读取ANPS证书文件,python,ios,django,apple-push-notifications,django-push-notifications,Python,Ios,Django,Apple Push Notifications,Django Push Notifications,我正在尝试在使用Django后端的iOS应用程序上实现推送通知。我将在前面解释一些上下文,以防它有启示性的信息。如果要直接转到问题,请转到问题部分 上下文 在此之后,我能够验证我的证书和配置文件是否正确配置,因为我的设备实际上正在接收由发送的推送通知 当然,要说得通,我的Django后端必须发送通知。为此,我安装了。在django设置文件中,我设置了APNS证书的路径。此文件需要是.pem文件,而不是Apple developer portal导出的普通.cer文件 要转换.cer文件,可以右键

我正在尝试在使用Django后端的iOS应用程序上实现推送通知。我将在前面解释一些上下文,以防它有启示性的信息。如果要直接转到问题,请转到问题部分

上下文 在此之后,我能够验证我的证书和配置文件是否正确配置,因为我的设备实际上正在接收由发送的推送通知

当然,要说得通,我的Django后端必须发送通知。为此,我安装了。在django设置文件中,我设置了APNS证书的路径。此文件需要是.pem文件,而不是Apple developer portal导出的普通.cer文件

要转换.cer文件,可以右键单击键链访问中的推送通知证书,然后导出.p12文件。要将.p12文件转换为所需的.pem,需要使用终端,并运行以下命令:

openssl pkcs12 -in [export p12 file].p12 -out [final pem file].pem -nodes -clcerts
为了确保我的.pem文件能够正常工作,我使用了以下命令

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert [final pem file].pem -key [final pem file].pem
我似乎得到了成功的响应(
已连接(00000003)…

问题 安装django推送通知后,即使我能够创建
APNSDevice
实例,也无法发送消息。这是我收到的错误:

File "/Users/joao/Code/code-vitae.com/env/lib/python3.4/site-packages/push_notifications/models.py", line 93, in send_message
    return apns_send_message(registration_id=self.registration_id, alert=message, **kwargs)
  File "/Users/joao/Code/code-vitae.com/env/lib/python3.4/site-packages/push_notifications/apns.py", line 209, in apns_send_message
    _apns_send(registration_id, alert, **kwargs)
  File "/Users/joao/Code/code-vitae.com/env/lib/python3.4/site-packages/push_notifications/apns.py", line 153, in _apns_send
    with closing(_apns_create_socket_to_push()) as socket:
  File "/Users/joao/Code/code-vitae.com/env/lib/python3.4/site-packages/push_notifications/apns.py", line 58, in _apns_create_socket_to_push
    return _apns_create_socket((SETTINGS["APNS_HOST"], SETTINGS["APNS_PORT"]))
  File "/Users/joao/Code/code-vitae.com/env/lib/python3.4/site-packages/push_notifications/apns.py", line 46, in _apns_create_socket
    raise ImproperlyConfigured("The APNS certificate file at %r is not readable: %s" % (certfile, e))
django.core.exceptions.ImproperlyConfigured: The APNS certificate file at '/Users/joao/Documents/Circli/Certificates/Pro_Key.pem' is not readable: 'utf-8' codec can't decode byte 0xe3 in position 4783: invalid continuation byte

这个错误使我怀疑我在创建pem文件时不知何故犯了错误。但是,如果我可以毫无问题地连接到Apple push服务器(如上下文中所示),这是怎么回事?

看起来在转换证书的过程中出现了问题


用于立即生成所需格式的推送证书。这是一个涵盖整个过程的过程

这是一个很长时间的痛苦,以至于我最终使用了一个PHP解决方案来处理通知。我使用了完全相同的PEM文件,它工作正常,所以我非常确定证书转换是正确的。无论如何,感谢您提供的工具(fastlane),它似乎非常有用。