Open Alir3z4 opened 7 years ago
Hello @Alir3z4
I have encountered an issue very similar to what you describe when I have DEBUG=True on my local machine with the apple sandbox configured and DEBUG=False on the production server against the production apns api. In my situation we had to ensure the correct APNS cert and TOPIC were set in each environment and the device had the correct token registered.
@Alir3z4 Does your Django project remain DEBUG=True and your app built in release mode? I was having same error. I fix it by adding APNS_USE_SANDBOX = False in settings.
I had DEBUG=False
in both production and staging environment of the app, however it was DEBUG=True
in development for sure.
I had the Topic set correctly as well, but that didn't work as well, tried many different settings but I wasn't able to get it working.
At the end we decided to get to Pusher.com for this, however I really wanted to get notifications working with Django Push Notifications.
However I still think I haven't tried all possible fixes for this scenario, at the moment I'm not working on that part of project and cannot confirm any suggested solutions can resolve the problem.
Please feel free to close this issue since.
@matthewh and @michaelluk thank you very much for the help.
@Alir3z4
Is your device token from the debug build or release build? Make sure the environments are synchronized.
I'm having same issue. It works on local machine (Mac OS Sierra) but doesn't work from remote instance on AWS EC2 (Ubuntu). Checked all the ports on EC2 and regenerated the certs multiple times. Still doesn't work.
In both cases DEBUG=True, APNS_USE_SANDBOX=True and topic set to app bundle-ID. Same settings on both systems using the development push certificate. Not getting any errors. It just silently fails.
On a whim installed Houston CLI and used it to send a push using the very same dev certificate from EC2. It worked. Appears to be isolated to django-push-notifications.
Exactly the same issue here as well! Waiting for help.
client = APNsClient(APNS_CERTIFICATE, use_sandbox=False, use_alternative_port=False) client.send_notification(token_hex, payload, APNS_TOPIC) Traceback (most recent call last): File "
", line 1, in File "/Users/Documents/Development/backend/lib/python3.6/site-packages/apns2/client.py", line 56, in send_notification raise exception_class_for_reason(result) apns2.errors.BadDeviceToken
Appears to be the issue in the """from apns2.client import APNsClient"""
Exactly the same issue here as well! Anything yet???.
same here
Update: fixed my issue - hadn't appreciated that a release build differs from an Ad Hoc distribution. Using the latter, submits the correct device token.
I now seem to be getting this error for some users. I definitely have the topic set correctly, APNS_USE_SANDBOX = False
and Debug = False
. Is there anything else I can check?
The same error on Python 3.6 + App 1.6.1
Same error, Python 3.6.7 + django-push-notifications 1.6.1
/usr/local/lib/python3.6/site-packages/push_notifications/apns.py in apns_send_message(registration_id, alert, application_id, certfile, **kwargs)
118 device.active = False
119 device.save()
--> 120 raise APNSServerError(status=reason_for_exception_class(apns2_exception.__class__))
121
122
APNSServerError: BadDeviceToken
Both on STAGING and PROD environment. Regenerated and tested our .pem certificate as per these instructions, made sure the device is posting a fresh token to the server, but still getting this error.
Configuration on STAGING:
{'APNS_CERTIFICATE': '/code/gopublic/cert/apn_dev.pem',
'APNS_HOST': 'gateway.push.apple.com',
'APNS_TOPIC': <bundle_id>,
'APNS_USE_ALTERNATIVE_PORT': False,
'APNS_USE_SANDBOX': True,
'CONFIG': 'push_notifications.conf.LegacyConfig',
'FCM_API_KEY': <key>,
'FCM_ERROR_TIMEOUT': None,
'FCM_MAX_RECIPIENTS': 1000,
'FCM_POST_URL': 'https://fcm.googleapis.com/fcm/send',
'GCM_API_KEY': <key>,
'GCM_ERROR_TIMEOUT': None,
'GCM_MAX_RECIPIENTS': 1000,
'GCM_POST_URL': 'https://android.googleapis.com/gcm/send',
'UPDATE_ON_DUPLICATE_REG_ID': False,
'USER_MODEL': 'users.User',
'WNS_ACCESS_URL': 'https://login.live.com/accesstoken.srf',
'WNS_PACKAGE_SECURITY_ID': None,
'WNS_SECRET_KEY': None,
'WP_CLAIMS': None,
'WP_ERROR_TIMEOUT': None,
'WP_POST_URL': {'CHROME': 'https://fcm.googleapis.com/fcm/send',
'FIREFOX': 'https://updates.push.services.mozilla.com/wpush/v2',
'OPERA': 'https://fcm.googleapis.com/fcm/send'},
'WP_PRIVATE_KEY': None}
Has anyone figured this out yet?
For me I had the same issue, I was using token based authentication and the error was regarding device tokens. Make sure your application setup is correct. Also you can try with use_sandbox flag as false. Sometimes the apps even on the test env are getting the tokens from the live account
What if you try to send a notification to a registration_id which doesn't exist?
I got the same error, BadDeviceToken
, when trying to send push notifications to ios devices (APNS). I thought registration_ids didn't exist or wasn't registered in firebase, but that's not true.
I've tried to send a test message thu Firebase to a workmate's device and the push notification was received.
So, the problem should be configuration's. Which I don't know how to solve...
I had this same issue and in my case, I was something like this:
[
...
"APNS_USE_SANDBOX": os.environ.get('APNS_USE_SANDBOX', False),
...
]
and the problem was that I was setting APNS_USE_SANDBOX
to False
in Heroku, and os.environ.get('APNS_USE_SANDBOX', False)
was returning False
as a String, and not a Boolean.
I'm not a professional developer so I don't know whether django-push-notifications
should handle this or it's a pretty standard thing.
I've configured my project for APNS. The notification goes to the iPhone device with the device
registration_id
on the local machine, but when I try to do the same thing on remote server it will give this error in the admin panel (using "send test message from admin actions"):Some messages could not be processed: 'BadDeviceToken'
, when trying to the same on the server shell (./manage.py shell
remote machine) I get the following traceback:I'm using Heroku.
Versions: