python - Django 推送通知 - 无法读取 ANPS 证书文件

标签 python ios django apple-push-notifications django-push-notifications

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

上下文

关注此tutorial ,我已经能够验证我的证书和配置文件是否正确配置,因为我的设备实际上正在接收由 APN Tester Free 发送的推送通知.

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

要转换 .cer 文件,可以在 Keychain Access 中右键单击 Push Notification Certificate 并导出一个 .p12 文件。要将 .p12 文件转换为所需的 .pem,需要使用 Terminal,然后运行以下命令:

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

我似乎得到了成功的响应(CONNECTED(00000003)...)

问题

安装 django-push-notification 后,即使我能够创建 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 推送服务器(如 Context 所示),这是怎么回事?

最佳答案

看起来您用于转换证书的过程有问题。

使用fastlane立即生成所需格式的推送证书。这是一个 blog post覆盖全过程

关于python - Django 推送通知 - 无法读取 ANPS 证书文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41839301/

相关文章:

ios - iOS-按地区更改UIDatePicker的语言

Python 亚马逊产品 API : Module not found error

python - Pygame 声音文件崩溃空闲

python - 为什么 [].append(1) 是 None

ios - 如何在ios中管理tableview内的按钮?

python - 在 DRF 中管理自定义序列化器的最佳方法是什么

python - 是否有 python 脚本来生成暴雪 API 访问 token ?

ios - 获取 iOS 今天扩展的宽度

mysql - Django将原始查询结果作为对象

javascript - Django Rest 框架 + ReactJS : Whats wrong with my API?