Code: Select all
from apnsclient import *
# For feedback or non-intensive messaging
con = Session().new_connection("feedback_sandbox", cert_file="apns.pem")
# New message to 3 devices. You app will show badge 10 over app's icon.
message = Message(["my_token"], alert="My message", badge=10)
# Send the message.
srv = APNs(con)
try:
res = srv.send(message)
except:
print ("Can't connect to APNs, looks like network is down")
else:
# Check failures. Check codes in APNs reference docs.
for token, reason in res.failed.items():
code, errmsg = reason
# according to APNs protocol the token reported here
# is garbage (invalid or empty), stop using and remove it.
print ("Device failed: {0}, reason: {1}".format(token, errmsg))
# Check failures not related to devices.
for code, errmsg in res.errors:
print ("Error: {}".format(errmsg))
# Check if there are tokens that can be retried
if res.needs_retry():
# repeat with retry_message or reschedule your task
retry_message = res.retry()
How resolve problem?from apnsclient import *
ImportError: No module named apnsclient