使用Python的Apple推送通知服务

使用Python的Apple推送通知服务,python,ssl,apple-push-notifications,Python,Ssl,Apple Push Notifications,各位, 当我使用下面的代码时,我遇到了一个关于APNs的问题。 我已经找到了很多种源代码来实现这个服务 import socket, ssl, json, struct import binascii deviceToken = 'XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX' thePayLoad = { 'aps': { 'alert':'Hello worl

各位,

当我使用下面的代码时,我遇到了一个关于APNs的问题。 我已经找到了很多种源代码来实现这个服务

import socket, ssl, json, struct import binascii

deviceToken = 'XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX' 

thePayLoad = {
     'aps': {
          'alert':'Hello world',
          'sound':'default',
          'badge':42,
          },
     'test_data': { 'foo': 'bar' },
     }

theCertfile = 'iphone_ck.pem'  

theHost = ( 'gateway.sandbox.push.apple.com', 2195 )

data = json.dumps( thePayLoad )

deviceToken = deviceToken.replace(' ','') 

byteToken = binascii.unhexlify(deviceToken)

theFormat = '!BH32sH%ds' % len(data) theNotification = struct.pack( theFormat, 0, 32, 

byteToken, len(data), data )

ssl_sock = ssl.wrap_socket( socket.socket( socket.AF_INET, socket.SOCK_STREAM ), certfile = theCertfile ) 

ssl_sock.connect( theHost )

ssl_sock.write( theNotification )

ssl_sock.close()
在我执行代码之后,我得到了下面的一个错误。 每次我尝试在GitHub上使用Pyans或在Google上使用APNWrapper时 我终于发现了这个错误。 所以,我决定自己实施

Traceback (most recent call last):
  File "testAPN.py", line 38, in <module>
    ssl_sock.connect( theHost )
  File "/usr/lib/python2.6/ssl.py", line 309, in connect
    self.do_handshake()
  File "/usr/lib/python2.6/ssl.py", line 293, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [Errno 1] _ssl.c:480: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 
alert handshake failure
回溯(最近一次呼叫最后一次):
文件“testAPN.py”,第38行,在
ssl_sock.connect(主机)
文件“/usr/lib/python2.6/ssl.py”,第309行,在connect中
self.do_握手
文件“/usr/lib/python2.6/ssl.py”,第293行,在do_握手中
赛尔夫:握手
ssl.SSLError:[Errno 1]\u ssl.c:480:error:14094410:ssl例程:SSL3\u读取字节:sslv3
警报握手失败
有谁能帮我找出这个错误,或者给我一些可能的指导
完成此功能?

我认为您应该尝试使用APNSWrapper模块完成此任务


它简单而通用。

我认为您应该尝试使用APNSWrapper模块来完成此任务


它简单而通用。

您可以使用的另一个库是


您不必与消息结构或连接抗争

您可以使用的另一个库是


您不必与消息结构或连接发生冲突

必须是配置问题,PyAPNS对我来说很好。我解决了这个问题,因为我在获取pem文件时犯了一个错误。必须是配置问题,PyAPNS对我来说很好。我解决了这个问题,因为我在获取pem文件时犯了一个错误。