web-push-libs / pywebpush

Python Webpush Data encryption library
Mozilla Public License 2.0
305 stars 52 forks source link

'unicode' object has no attribute 'get' #70

Closed rishabhnag1 closed 6 years ago

rishabhnag1 commented 6 years ago

Hey there, I'm trying to make a webpush call, but its giving me the error: 'unicode' object has no attribute 'get' It looks like that error is being triggered by url = urlparse(subscription_info.get('endpoint'))' Any idea what might be causing this?

jrconlin commented 6 years ago

off hand, I'd suspect that you're passing a string value for subscription info rather than a dict. subscription_info is a JSON blob, but it needs to be converted to a python dict object before it's useful. webpush does this for you. If you're using the library form, you should probably call json.loads(subscription_info).

rishabhnag1 commented 6 years ago

yeah, that fixed it, thanks! as a side note the call is now returning Error 400, Unauthorized Registration. Was wondering if you've seen that come up before, or have an idea as to what it might be caused by

jrconlin commented 6 years ago

All kinds of things, unfortunately.

Things to check: 1) You're using the matching private key for the public key you used to register the endpoint. 2) your "sub" is a proper "mailto:name@domain" url specifier. (e.g. "mailto:bob@example.com") 3) if you've specified an "exp" that it's no more than now+ 24 hours and that your server's clock is reasonably accurate.

Firefox's server is a good deal more informative about the type of thing that may have gone wrong, so it' might be worth trying using Developer Edition and seeing what the curl response says.

https://blog.mozilla.org/services/2016/04/04/using-vapid-with-webpush/ goes into probably inordinate detail about VAPID headers, if it might help.