Django推送通知无法读取ANPS证书fi

2024-03-29 13:11:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在使用Django后端的iOS应用程序上实现推送通知。我会先解释一些背景,以防有透露的信息。如果您想直接找到问题,请转到问题部分。在

上下文

{a1}我的配置文件{a1}已经正确地配置了^我的设备^发送的通知。在

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

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

openssl pkcs12 -in [export p12 file].p12 -out [final pem file].pem -nodes -clcerts

为了确保我的.pem文件能够正常工作,我使用了以下命令

^{pr2}$

我似乎得到了成功的答复(CONNECTED(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推送服务器(如上下文中所示),这是怎么回事?在


Tags: 文件inenvcomapnscodepempush