使用pywebpush的webpush django

问题描述

我编写了以下简单代码,将Web推送消息发送到Angular应用程序:

profile = Profile.objects.filter(user__id=1).first()
subscription_info = {
    "endpoint": profile.notification_url,"keys": {
          "auth": profile.auth,"p256dh": profile.p256dh
        }
}

data = {"notification":{"title":"Notifications","body":"Test","icon":"https://www.shareicon.net/data/256x256/2015/10/02/110808_blog_512x512.png","vibrate":[100,50,100],"data":{"url":"https://x.com"}}}

webpush(subscription_info,data,vapid_private_key="valid_key",vapid_claims={"sub": "mailto: [email protected]"})

执行此操作后,我得到以下错误

content[i:i + chunk_size],TypeError: unhashable type: 'slice'

将“ data”变量更改为仅一个类似于“ test”的字符串,它可以正常执行,但是随后我在Google Chrome浏览器中的Angular应用程序给了我以下错误

ngsw-worker.js:2031 Uncaught SyntaxError: Unexpected token T in JSON at position 0

如何使用pywebpush将Web推送通知发送到Angular(在Chrome中)?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)