StackOverflow!
Я пытаюсь отправить уведомления Web Push из моего приложения Flask, используя библиотеки pywebpush и py_vapid для аутентификации с помощью ключей VAPID, но Я столкнулся с ошибкой, утверждающей, что поле aud отсутствует в моих утверждениях VAPID.
Вот код, который я использую для отправки уведомления:
Код: Выделить всё
from pywebpush import webpush, WebPushException
vapid_private_key_pem = "KE0RL_B2SY1AVcpHRWgTzC68or6cLC4RZaHmkM4ZsLk"
def send_push_notification(subscription_info, data):
vapid_claims = {
"sub": "mailto:vadimshiba@duck.com",
"aud": "https://chat.bitsquad.ru/"
}
try:
response = webpush(
subscription_info=subscription_info,
data=data,
vapid_private_key=vapid_private_key_pem,
vapid_claims=vapid_claims
)
print("Push sent successfully: ", response)
return True
except WebPushException as ex:
print("Web push failure: ", repr(ex))
return False
Код: Выделить всё
ValueError: Missing 'aud' from claims. 'aud' is the scheme, host and optional port for this transaction e.g. https://example.com:8080
- Double-checking VAPID claims: I re-checked the format and content of vapid_claims, ensuring that aud, sub, and other necessary fields accurately met the specifications.
- Updating libraries: I made sure I was using the latest versions of the pywebpush and py_vapid libraries to eliminate the possibility of errors due to outdated software.
- Logging: Directly before sending the notification, I added logging for key variables, including vapid_claims and subscription_info, to ensure their correctness.
- Checking the private key format: I re-verified the format of my VAPID private key, ensuring it met the expected standards and was correctly used in the code.
Источник: https://stackoverflow.com/questions/781 ... with-vapid