### Subscription Info Example (JSON) Source: https://github.com/web-push-libs/pywebpush/blob/main/README.md Example JSON structure for push subscription information, typically returned by a Push subscribe method. Includes endpoint URL and encryption keys (auth and p256dh). ```json { "endpoint": "https://push...", "keys": { "auth": "ab01...", "p256dh": "aa02..." } } ``` -------------------------------- ### Handle Push Notification with Error Handling Source: https://github.com/web-push-libs/pywebpush/blob/main/README.md A comprehensive example showing how to send a push notification using the webpush function while catching and processing potential WebPushExceptions. ```python from pywebpush import webpush, WebPushException try: webpush( subscription_info={ "endpoint": "https://push.example.com/v1/12345", "keys": { "p256dh": "0123abcde...", "auth": "abc123..." }}, data="Mary had a little lamb, with a nice mint jelly", vapid_private_key="path/to/vapid_private.pem", vapid_claims={ "sub": "mailto:YourNameHere@example.org", } ) except WebPushException as ex: print("I'm sorry, Dave, but I can't do that: {}", repr(ex)) if ex.response is not None and ex.response.json(): extra = ex.response.json() print("Remote service replied with a {}:{}, {}", extra.code, extra.errno, extra.message ) ``` -------------------------------- ### Windows Specific Headers (JSON) Source: https://github.com/web-push-libs/pywebpush/blob/main/README.rst Example content for a Windows headers file, including the required X-WNS-Type and suggested TTL and Content-Type headers for specific notification types like wns/toast. ```json { "X-WNS-Type": "wns/toast", "TTL": 600, "Content-Type": "text/xml" } ``` -------------------------------- ### Web Push Notification Example with Error Handling Source: https://github.com/web-push-libs/pywebpush/blob/main/README.rst Demonstrates sending a web push notification with comprehensive error handling using a try-except block. It catches `WebPushException` and prints detailed error information, including any response from the remote service. ```python from pywebpush import webpush, WebPushException try: webpush( subscription_info={ "endpoint": "https://push.example.com/v1/12345", "keys": { "p256dh": "0123abcde...", "auth": "abc123..." }}, data="Mary had a little lamb, with a nice mint jelly", vapid_private_key="path/to/vapid_private.pem", vapid_claims={ "sub": "mailto:YourNameHere@example.org", } ) except WebPushException as ex: print("I'm sorry, Dave, but I can't do that: {}", repr(ex)) # Mozilla returns additional information in the body of the response. if ex.response is not None and ex.response.json(): extra = ex.response.json() print("Remote service replied with a {}:{}, {}", extra.code, extra.errno, extra.message ) ``` -------------------------------- ### Send WebPush Notification with Windows Headers (Bash) Source: https://github.com/web-push-libs/pywebpush/blob/main/README.md Sends a web push notification with specific headers required by Windows, including TTL and Content-Type. Uses separate files for data, subscription info, headers, and claims. ```bash pywebpush --data stuff_to_send.xml \ --info edge_user_info.json \ --head windows_headers.json \ --claims vapid_claims.json ``` -------------------------------- ### pywebpush Command Line Interface Usage Source: https://context7.com/web-push-libs/pywebpush/llms.txt Provides a CLI tool for sending push notifications from shell scripts or for manual testing. It reads subscription information and data from JSON files. Supports generating VAPID keys, sending notifications, enabling verbose output for debugging, and generating curl commands. ```bash # Generate VAPID keys (using py_vapid) vapid --gen # Create subscription info file (subscription.json) cat > subscription.json << 'EOF' { "endpoint": "https://updates.push.services.mozilla.com/push/v1/gAA...", "keys": { "auth": "k8JV6sjdbhAi1n3_LDBLvA", "p256dh": "BOrnIslXrUow2VAzKCUAE4sIbK00daEZCswOcf8m3TF8V82B..." } } EOF # Create VAPID claims file (claims.json) cat > claims.json << 'EOF' { "sub": "mailto:admin@example.com" } EOF # Create message file (message.txt) echo '{"title": "Test", "body": "Hello World"}' > message.txt # Send push notification pywebpush --data message.txt --info subscription.json --claims claims.json --key private_key.pem # Send with verbose output for debugging pywebpush --data message.txt --info subscription.json --claims claims.json --key private_key.pem --verbose # Generate curl command instead of sending pywebpush --data message.txt --info subscription.json --claims claims.json --key private_key.pem --curl ``` -------------------------------- ### Windows Headers Configuration (JSON) Source: https://github.com/web-push-libs/pywebpush/blob/main/README.md JSON object defining additional headers for Windows push notifications, including 'X-WNS-Type', 'TTL', and 'Content-Type'. These are non-standard and may be rejected by other platforms. ```json { "X-WNS-Type": "wns/toast", "TTL": 600, "Content-Type": "text/xml" } ``` -------------------------------- ### Send Windows Notification Service (WNS) Push Source: https://context7.com/web-push-libs/pywebpush/llms.txt Demonstrates sending a toast notification to Windows endpoints. Includes CLI commands for header/payload creation and a Python implementation using the webpush function. ```bash cat > wns_headers.json << 'EOF' { "X-WNS-Type": "wns/toast", "TTL": 600, "Content-Type": "text/xml" } EOF cat > toast.xml << 'EOF' New Message You have a new notification! EOF pywebpush --data toast.xml \ --info edge_subscription.json \ --head wns_headers.json \ --claims claims.json \ --key private_key.pem \ --wns ``` ```python from pywebpush import webpush windows_subscription = { "endpoint": "https://wns2-par02p.notify.windows.com/...", "keys": {"p256dh": "...", "auth": "..."} } wns_headers = { "X-WNS-Type": "wns/toast", "Content-Type": "text/xml" } toast_xml = """ Hello from pywebpush! """ response = webpush( subscription_info=windows_subscription, data=toast_xml, vapid_private_key="/path/to/private.pem", vapid_claims={"sub": "mailto:admin@example.com"}, headers=wns_headers, ttl=600 ) ``` -------------------------------- ### Send WebPush Notification via Command Line (Bash) Source: https://github.com/web-push-libs/pywebpush/blob/main/README.md Encrypts and sends the contents of a data file to a subscription endpoint using the pywebpush command-line tool. Requires data file and subscription info file. ```bash ./bin/pywebpush --data stuff_to_send.data --info subscription.info ``` -------------------------------- ### Generate VAPID Private Key Source: https://github.com/web-push-libs/pywebpush/blob/main/README.md A command-line instruction to generate a VAPID EC2 private key in PEM format using OpenSSL, which is required for authenticating push requests. ```bash openssl ecparam -name prime256v1 -genkey -noout -out private_key.pem ``` -------------------------------- ### Send Push Notification with webpush() Source: https://github.com/web-push-libs/pywebpush/blob/main/README.md Demonstrates the 'One Call' method to send encrypted data to a push service. It requires subscription information, the data payload, and VAPID authentication details. ```python from pywebpush import webpush webpush(subscription_info, data, vapid_private_key="Private Key or File Path", vapid_claims={"sub": "mailto:YourEmailAddress"}) ``` -------------------------------- ### Manage Empty Payloads and NoData Exception Source: https://context7.com/web-push-libs/pywebpush/llms.txt Illustrates handling the NoData exception when attempting to encode empty payloads. It also demonstrates how to send a silent push (tickle) by providing an empty string and setting TTL to 0. ```python from pywebpush import WebPusher, NoData subscription_info = { "endpoint": "https://push.example.com/v1/user123", "keys": {"p256dh": "...", "auth": "..."} } pusher = WebPusher(subscription_info) try: pusher.encode("") except NoData: print("Cannot encode empty data - send notification without payload instead") response = pusher.send(data="", headers={"TTL": "0"}) ``` -------------------------------- ### Send Web Push Notification via Command Line (Bash) Source: https://github.com/web-push-libs/pywebpush/blob/main/README.rst Encrypts and sends data using the pywebpush command-line tool. Requires data and subscription info files. Supports additional options for headers and claims, particularly useful for Windows notifications. ```bash ./bin/pywebpush --data stuff_to_send.data --info subscription.info ``` ```bash pywebpush --data stuff_to_send.xml \ --info edge_user_info.json \ --head windows_headers.json \ --claims vapid_claims.json ``` -------------------------------- ### Handle WebPushException and Service Errors Source: https://context7.com/web-push-libs/pywebpush/llms.txt Shows how to catch WebPushException during push delivery. It demonstrates extracting HTTP status codes and parsing structured error responses from services like Mozilla autopush. ```python from pywebpush import webpush, WebPushException subscription_info = { "endpoint": "https://updates.push.services.mozilla.com/push/v1/invalid", "keys": {"p256dh": "...", "auth": "..."} } try: webpush( subscription_info=subscription_info, data="Test message", vapid_private_key="private.pem", vapid_claims={"sub": "mailto:admin@example.com"} ) except WebPushException as ex: print(f"Exception: {ex.message}") if ex.response is not None: print(f"HTTP Status: {ex.response.status_code}") print(f"Response Body: {ex.response.text}") try: error_data = ex.response.json() print(f"Error Code: {error_data.get('code')}") except ValueError: pass ``` -------------------------------- ### PyWebPush Command Line Tool Source: https://github.com/web-push-libs/pywebpush/blob/main/README.rst Utilizes the stand-alone `pywebpush` command for sending push notifications from the command line, supporting data and subscription info files. ```APIDOC ## Command Line Tool: pywebpush ### Description The `pywebpush` command-line tool allows you to send push notifications without writing custom code. It uses separate files for message data and subscription information. ### Usage ```bash ./bin/pywebpush --data --info [options] ``` ### Parameters * **--data** (file path) - Required - Path to the file containing the message data. * **--info** (file path) - Required - Path to the JSON file containing subscription information (endpoint, keys). * **--head** (file path) - Optional - Path to a JSON file containing additional headers (e.g., for Windows notifications). * **--claims** (file path) - Optional - Path to a JSON file containing VAPID claims. ### Example ```bash ./bin/pywebpush --data stuff_to_send.data --info subscription.info ``` ### Special Instructions #### Windows Notifications Microsoft requires specific headers for Windows notifications. These can be provided via the `--head` option. Example `windows_headers.json`: ```json { "X-WNS-Type": "wns/toast", "TTL": 600, "Content-Type": "text/xml" } ``` Example command with Windows headers: ```bash pywebpush --data stuff_to_send.xml --info edge_user_info.json --head windows_headers.json --claims vapid_claims.json ``` #### Google Cloud Messaging (GCM) Note: GCM has been sunset. Use Firebase Cloud Messaging (FCM) instead. Direct sending to FCM is not supported by this library. The `gcm_key` was disabled in June 2024. Sending messages to Google Chrome users should not be impacted. ``` -------------------------------- ### webpush_async() - Asynchronous Push Sender Source: https://context7.com/web-push-libs/pywebpush/llms.txt An asynchronous version of the push sender designed for use within asyncio applications, supporting efficient connection pooling via aiohttp. ```APIDOC ## POST webpush_async() ### Description Sends a push notification asynchronously, ideal for high-concurrency applications. ### Method POST (Internal HTTP request to push service) ### Parameters #### Request Body - **subscription_info** (dict) - Required - Subscription data. - **data** (str) - Required - Payload string. - **vapid_private_key** (str) - Required - VAPID private key. - **vapid_claims** (dict) - Required - VAPID claims. - **content_encoding** (str) - Optional - Encryption type (e.g., "aes128gcm"). - **ttl** (int) - Optional - Time-to-live in seconds. ### Response #### Success Response (200/201) - **status** (int) - HTTP status code from the push service. ### Response Example { "status": 201 } ``` -------------------------------- ### WebPusher - Low-Level Push Class Source: https://context7.com/web-push-libs/pywebpush/llms.txt A class-based interface for fine-grained control over the push process, allowing for session reuse and custom header injection. ```APIDOC ## POST WebPusher.send() ### Description Sends a notification using a pre-configured WebPusher instance, allowing for custom headers and session management. ### Method POST ### Parameters #### Request Body - **data** (str) - Required - The message payload. - **headers** (dict) - Optional - Custom HTTP headers (e.g., {"Urgency": "high"}). - **ttl** (int) - Optional - Time-to-live in seconds. - **content_encoding** (str) - Optional - Encryption scheme. - **timeout** (int) - Optional - Request timeout. ### Response #### Success Response (200/201) - **status_code** (int) - HTTP status code. - **text** (str) - Response body from the push service. ### Response Example { "status_code": 201, "text": "Created" } ``` -------------------------------- ### Send Push Notification (Asynchronous) Source: https://context7.com/web-push-libs/pywebpush/llms.txt Sends a push notification asynchronously using `webpush_async`. This is suitable for asyncio applications and can optionally reuse an `aiohttp.ClientSession`. It requires similar parameters to the synchronous version, including subscription info, data, VAPID key, and claims. ```python import asyncio from pywebpush import webpush_async, WebPushException async def send_notification(): subscription_info = { "endpoint": "https://updates.push.services.mozilla.com/push/v1/gAA...", "keys": { "p256dh": "BOrnIslXrUow2VAzKCUAE4sIbK00daEZCswOcf8m3TF8V82B...", "auth": "k8JV6sjdbhAi1n3_LDBLvA" } } try: response = await webpush_async( subscription_info=subscription_info, data='{"title": "New Alert", "body": "Check your dashboard"}', vapid_private_key="MHcCAQEEIPeN1iAipHbt8...", # Base64 DER key vapid_claims={"sub": "mailto:alerts@example.com"}, content_encoding="aes128gcm", ttl=86400 ) print(f"Async push sent: {response.status}") except WebPushException as ex: print(f"Async push failed: {ex}") asyncio.run(send_notification()) ``` -------------------------------- ### Encode Data for WebPush (Python) Source: https://github.com/web-push-libs/pywebpush/blob/main/README.md Encodes binary data for use in WebPush notifications. Handles content encoding and raises WebPushException on error. It's recommended not to call this if there is no data. ```python from pywebpush import WebPush # Assuming subscription_info is already defined data = b'Your data to encode' webpush_instance = WebPush(subscription_info) encoded_data = webpush_instance.encode(data) print(encoded_data) ``` -------------------------------- ### Send Push Notification (Synchronous) Source: https://context7.com/web-push-libs/pywebpush/llms.txt Sends a push notification using the `webpush` function. It requires subscription information, the data payload, VAPID private key, and optional claims, TTL, and timeout. Handles encryption and HTTP delivery in one call. Errors are caught via `WebPushException`. ```python from pywebpush import webpush, WebPushException # Subscription info obtained from browser's PushManager.subscribe() subscription_info = { "endpoint": "https://fcm.googleapis.com/fcm/send/abc123...", "keys": { "p256dh": "BOrnIslXrUow2VAzKCUAE4sIbK00daEZCswOcf8m3TF8V82B-OpOg5JbmYLg44kRcvQC1E2gMJshsUYA-_zMPR8", "auth": "k8JV6sjdbhAi1n3_LDBLvA" } } # Send notification with VAPID authentication try: response = webpush( subscription_info=subscription_info, data="You have a new message!", vapid_private_key="/path/to/vapid_private.pem", # or base64-encoded DER string vapid_claims={"sub": "mailto:admin@example.com"}, ttl=3600, # Time-to-live in seconds timeout=30 # Request timeout ) print(f"Push sent successfully: {response.status_code}") except WebPushException as ex: print(f"Push failed: {ex}") if ex.response is not None: error_info = ex.response.json() print(f"Error code: {error_info.get('errno')}, Message: {error_info.get('message')}") ``` -------------------------------- ### Send WebPush Notification (Python) Source: https://github.com/web-push-libs/pywebpush/blob/main/README.md Sends a web push notification to a user on Chrome. Requires subscription information, data to send, and optionally headers and TTL. ```python from pywebpush import WebPusher # Assuming subscription_info is already defined data = b'Your notification data' headers = {'Urgency': 'high'} ttl = 3600 pusher = WebPusher(subscription_info) response = pusher.send(data, headers, ttl) print(response) ``` -------------------------------- ### Send Notifications Asynchronously with WebPusher.send_async Source: https://context7.com/web-push-libs/pywebpush/llms.txt Provides asynchronous sending capabilities using aiohttp sessions for efficient connection reuse across multiple push operations. This method is ideal for batch sending notifications in an async environment. It takes the message data, optional headers, TTL, and content encoding as parameters. ```python import asyncio import aiohttp from pywebpush import WebPusher async def send_multiple_notifications(subscriptions, message): async with aiohttp.ClientSession() as session: tasks = [] for sub_info in subscriptions: pusher = WebPusher(sub_info, aiohttp_session=session) task = pusher.send_async( data=message, headers={"Urgency": "normal"}, ttl=600, content_encoding="aes128gcm" ) tasks.append(task) results = await asyncio.gather(*tasks, return_exceptions=True) for i, result in enumerate(results): if isinstance(result, Exception): print(f"Subscription {i} failed: {result}") else: print(f"Subscription {i} sent: status {result.status}") # Example usage subscriptions = [ {"endpoint": "https://push.example.com/user1", "keys": {"p256dh": "...", "auth": "..."}}, {"endpoint": "https://push.example.com/user2", "keys": {"p256dh": "...", "auth": "..."}}, ] asyncio.run(send_multiple_notifications(subscriptions, "Batch notification")) ``` -------------------------------- ### Handling Windows Notification Service (WNS) Headers Source: https://context7.com/web-push-libs/pywebpush/llms.txt Microsoft Windows requires additional non-standard headers for push notifications. The pywebpush CLI supports the `--wns` flag and custom header options to facilitate sending notifications to Windows endpoints, ensuring compatibility with the WNS requirements. ```bash # Example usage with --wns flag (specific command not provided in source, conceptual) # pywebpush --data message.txt --info subscription.json --key private_key.pem --wns # Example of adding custom headers (conceptual) # pywebpush --data message.txt --info subscription.json --key private_key.pem --header "X-WNS-Type: ..." ``` -------------------------------- ### Send Push Notification Source: https://github.com/web-push-libs/pywebpush/blob/main/README.rst Sends data to a user via push notification. Supports various options for customization and debugging. ```APIDOC ## POST /send ### Description Sends the provided data using additional parameters. On error, returns a WebPushException. ### Method POST ### Endpoint /send ### Parameters #### Path Parameters None #### Query Parameters * **ttl** (integer) - Optional - Message Time To Live on Push Server waiting for the client to reconnect (in seconds). * **reg_id** (string) - Optional - Google Cloud Messaging registration ID (will be extracted from endpoint if not specified). * **content_encoding** (string) - Optional - ECE content encoding type (defaults to “aes128gcm”). * **curl** (boolean) - Optional - Do not execute the POST, but return as a `curl` command. This will write the encrypted content to a local file named `encrpypted.data`. This command is meant to be used for debugging purposes. * **timeout** (integer) - Optional - Timeout for requests POST query. See `requests documentation `__. #### Request Body * **data** (binary string) - Required - Binary string of data to send. * **headers** (dict) - Optional - A `dict` containing any additional headers to send. ### Request Example ```json { "data": "binary_data_here", "headers": { "Authorization": "Bearer YOUR_TOKEN" } } ``` ### Response #### Success Response (200) Returns a success status or confirmation of the sent notification. #### Response Example ```json { "status": "success", "message_id": "12345abcde" } ``` ``` -------------------------------- ### Encode Data for Web Push (Python) Source: https://github.com/web-push-libs/pywebpush/blob/main/README.rst Encodes binary data for future use with a specified content encoding. Returns a WebPushException on error. Note that encoding is a no-op if the data is not present or empty, and it's best not to call this method in such cases. ```python encoded_data = WebPush(subscription_info).encode(data) ``` -------------------------------- ### webpush() - Synchronous Push Sender Source: https://context7.com/web-push-libs/pywebpush/llms.txt The primary high-level function for sending push notifications synchronously. It handles subscription parsing, encryption, and VAPID authentication in a single call. ```APIDOC ## POST webpush() ### Description Sends a push notification to a browser subscription using synchronous HTTP requests. ### Method POST (Internal HTTP request to push service) ### Parameters #### Request Body - **subscription_info** (dict) - Required - Subscription data containing endpoint and keys (p256dh, auth). - **data** (str/bytes) - Required - The payload to send. - **vapid_private_key** (str) - Required - Path to PEM file or base64-encoded DER string. - **vapid_claims** (dict) - Required - VAPID claims (e.g., {"sub": "mailto:admin@example.com"}). - **ttl** (int) - Optional - Time-to-live in seconds. - **timeout** (int) - Optional - Request timeout in seconds. ### Response #### Success Response (200/201) - **status_code** (int) - HTTP status code from the push service. ### Response Example { "status_code": 201 } ``` -------------------------------- ### Generate Curl Debug Output for Webpush Source: https://context7.com/web-push-libs/pywebpush/llms.txt Generates a curl command string instead of sending the push notification, which is invaluable for debugging. This functionality is supported by both the `webpush()` function and the `WebPusher.send()` method when the `curl=True` parameter is provided. The output includes headers and data suitable for direct execution with curl. ```python from pywebpush import webpush subscription_info = { "endpoint": "https://fcm.googleapis.com/fcm/send/abc123", "keys": { "p256dh": "BOrnIslXrUow2VAzKCUAE4sIbK00daEZCswOcf8m3TF8V82B-OpOg5JbmYLg44kRcvQC1E2gMJshsUYA-_zMPR8", "auth": "k8JV6sjdbhAi1n3_LDBLvA" } } # Get curl command instead of sending curl_command = webpush( subscription_info=subscription_info, data="Debug test message", vapid_claims={"sub": "mailto:dev@example.com"}, vapid_private_key="MHcCAQEEIPeN1iAipHbt8...", curl=True ) print(curl_command) # Output: # curl -vX POST https://fcm.googleapis.com/fcm/send/abc123 \ # -H "content-encoding: aes128gcm" \ # -H "authorization: vapid t=eyJ0eXAi...,k=BA..." \ # -H "ttl: 0" \ # -H "content-length: 128" \ # --data-binary @encrypted.data ``` -------------------------------- ### Low-Level Push Notification Sending Source: https://context7.com/web-push-libs/pywebpush/llms.txt Uses the `WebPusher` class for fine-grained control over sending push notifications. It allows for separating encryption and sending steps and can utilize a `requests.Session` for connection pooling. Useful for sending multiple messages to the same recipient. ```python from pywebpush import WebPusher, WebPushException import requests subscription_info = { "endpoint": "https://push.example.com/v1/user123", "keys": { "p256dh": "BOrnIslXrUow2VAzKCUAE4sIbK00daEZCswOcf8m3TF8V82B-OpOg5JbmYLg44kRcvQC1E2gMJshsUYA-_zMPR8", "auth": "k8JV6sjdbhAi1n3_LDBLvA" } } # Create pusher instance (optionally with session for connection reuse) session = requests.Session() pusher = WebPusher(subscription_info, requests_session=session, verbose=True) # Send with custom headers and TTL response = pusher.send( data="Hello from pywebpush!", headers={"Urgency": "high"}, ttl=300, content_encoding="aes128gcm", timeout=10 ) print(f"Response: {response.status_code} - {response.text}") ``` -------------------------------- ### Encode Data for Push Notification Source: https://github.com/web-push-libs/pywebpush/blob/main/README.rst Encodes the provided data for future use in push notifications. Handles potential errors by returning a WebPushException. ```APIDOC ## POST /encode ### Description Encodes the `data` for future use. On error, returns a WebPushException. This will return a `NoData` exception if the data is not present or empty. It is completely valid to send a WebPush notification with no data, but encoding is a no-op in that case. Best not to call it if you don’t have data. ### Method POST ### Endpoint /encode ### Parameters #### Path Parameters None #### Query Parameters * **content_encoding** (string) - Optional - ECE content encoding type (defaults to “aes128gcm”). #### Request Body * **data** (binary string) - Required - Binary string of data to send. ### Request Example ```json { "data": "binary_data_to_encode" } ``` ### Response #### Success Response (200) Returns the encoded data. #### Response Example ```json { "encoded_data": "base64_encoded_string" } ``` ``` -------------------------------- ### Send Web Push Notification (Python) Source: https://github.com/web-push-libs/pywebpush/blob/main/README.rst Sends data using additional parameters like headers, TTL, and content encoding. It can return a WebPushException on error or a curl command for debugging if specified. Dependencies include the 'requests' library for timeouts. ```python WebPusher(subscription_info).send(data, headers, ttl) ``` -------------------------------- ### Encrypt Data with WebPusher.encode Source: https://context7.com/web-push-libs/pywebpush/llms.txt Encrypts data using HTTP Encrypted Content Encoding without sending it. Useful for pre-encrypting payloads or debugging. Returns a dictionary with the encrypted body and necessary headers. Supports 'aes128gcm' and legacy 'aesgcm' content encodings. ```python from pywebpush import WebPusher, NoData subscription_info = { "endpoint": "https://push.example.com/v1/user123", "keys": { "p256dh": "BOrnIslXrUow2VAzKCUAE4sIbK00daEZCswOcf8m3TF8V82B-OpOg5JbmYLg44kRcvQC1E2gMJshsUYA-_zMPR8", "auth": "k8JV6sjdbhAi1n3_LDBLvA" } } pusher = WebPusher(subscription_info) # Encode with RFC 8188 standard (aes128gcm) try: encoded = pusher.encode(b"Encrypted message content", content_encoding="aes128gcm") print(f"Encrypted body length: {len(encoded['body'])} bytes") except NoData: print("No data provided for encoding") # Encode with legacy aesgcm (deprecated, for older browsers) encoded_legacy = pusher.encode(b"Legacy encrypted content", content_encoding="aesgcm") print(f"Crypto-Key header: {encoded_legacy.get('crypto_key')}") print(f"Salt header: {encoded_legacy.get('salt')}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.