---
source_url: https://www.pubnub.com/docs/sdks/python/troubleshoot
title: Troubleshooting Python SDK
updated_at: 2026-06-12T11:26:29.740Z
sdk_name: PubNub Python SDK
sdk_version: 10.7.0
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Troubleshooting Python SDK

PubNub Python SDK, use the latest version: 10.7.0

Install:

```bash
pip install pubnub@10.7.0
```

This page explains how to identify your SDK version and handle errors in the PubNub Python Software Development Kit (SDK).

## How to find the version of your SDK

### Access your SDK version via constant

The following snippet demonstrates how to retrieve and display the SDK version using the `PubNub` class.

### Steps to access the SDK version

1. Import the required modules.
2. Retrieve the version with `PubNub.SDK_VERSION`.
3. Log or print the version for future reference.

```python
import os
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub

def main():
    # Display the current SDK version
    print(f"Current PubNub SDK Version: {PubNub.SDK_VERSION}")
    
    # Optional: You can also initialize a PubNub instance and check the version
    pn_config = PNConfiguration()
    pn_config.subscribe_key = os.getenv('SUBSCRIBE_KEY', 'demo')  # Replace 'demo' with your subscribe key from the PubNub Admin Portal
    pn_config.user_id = os.getenv('USER_ID', 'my_custom_user_id')
    
    pubnub = PubNub(pn_config)
    print(f"Initialized PubNub with SDK Version: {pubnub.SDK_VERSION}")

if __name__ == "__main__":
    main()
```

## Error handling with sync()

When you call `sync()`, errors are wrapped by either `Envelope` or `PubNubException`. Both provide the following fields:

* e.result - a request result object in case of success, otherwise None
* e.status - a PNStatus object with useful information about the finished request. You can check whether it was an error or a success using the e.is_error() helper.

### sync() usage

```python
import os
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
from pubnub.exceptions import PubNubException

def publish_message(pubnub: PubNub):
    try:
        envelope = pubnub.publish() \
            .channel("my_channel") \
            .message("hello!") \
            .sync()
        print(f"Published message with timetoken: {envelope.result.timetoken}")
        print(f"Full result: {str(envelope.result)}")
    except PubNubException as e:
        print(f"Error: {str(e)}")
        print(f"Error category: {e.status.category}")

def main():
    # Configuration for PubNub instance
    pn_config = PNConfiguration()
    pn_config.subscribe_key = os.getenv('SUBSCRIBE_KEY', 'demo')  # Replace 'demo' with your subscribe key from the PubNub Admin Portal
    pn_config.publish_key = os.getenv('PUBLISH_KEY', 'demo')  # Replace 'demo' with your publish key from the PubNub Admin Portal
    pn_config.user_id = os.getenv('USER_ID', 'my_custom_user_id')

    # Initialize PubNub client
    pubnub = PubNub(pn_config)

    # Publish a message
    publish_message(pubnub)

if __name__ == "__main__":
    main()
```

## Error handling with async()

When you call `async()`, you can check for errors using the `status.is_error()` helper:

```python
import os
import time
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
from pubnub.callbacks import SubscribeCallback
from pubnub.enums import PNStatusCategory, PNOperationType

class MySubscribeCallback(SubscribeCallback):
    def status(self, pubnub, status):
        if status.is_error():
            print(f"Error: {str(status.error_data.exception)}")
            print(f"Error category: {status.category}")
        elif status.category == PNStatusCategory.PNConnectedCategory:
            print("Connected to PubNub!")
        elif status.category == PNStatusCategory.PNReconnectedCategory:
            print("Reconnected to PubNub!")
        elif status.category == PNStatusCategory.PNDisconnectedCategory:
            print("Disconnected from PubNub!")

    def message(self, pubnub, message):
        print(f"Received message: {str(message.message)}")
        print(f"Channel: {message.channel}")
        print(f"Publisher: {message.publisher}")
        print(f"Timetoken: {message.timetoken}")

    def presence(self, pubnub, presence):
        print(f"Presence event: {presence.event}")
        print(f"UUID: {presence.uuid}")
        print(f"Channel: {presence.channel}")
        print(f"Occupancy: {presence.occupancy}")

def main():
    # Configuration for PubNub instance
    pn_config = PNConfiguration()
    pn_config.subscribe_key = os.getenv('SUBSCRIBE_KEY', 'demo')  # Replace 'demo' with your subscribe key from the PubNub Admin Portal
    pn_config.publish_key = os.getenv('PUBLISH_KEY', 'demo')  # Replace 'demo' with your publish key from the PubNub Admin Portal
    pn_config.user_id = os.getenv('USER_ID', 'my_custom_user_id')

    # Initialize PubNub client
    pubnub = PubNub(pn_config)

    # Add listener
    listener = MySubscribeCallback()
    pubnub.add_listener(listener)

    # Subscribe to channel
    pubnub.subscribe().channels("my_channel").execute()
    
    print("Subscribed to 'my_channel'. Waiting for messages...")
    
    # Example of a publish operation with a callback
    def publish_callback(result, status):
        if status.is_error():
            print(f"Error: {str(status.error_data.exception)}")
            print(f"Error category: {status.category}")
        else:
            print(f"Publish successful: {str(result)}")
    
    # Publish a message with the callback
    pubnub.publish().channel("my_channel").message("Hello from callback example!").pn_async(publish_callback)
    
    # Keep the program running to receive messages
    try:
        time.sleep(10)  # Run for 10 seconds
    except KeyboardInterrupt:
        pass
    finally:
        pubnub.unsubscribe_all()
        pubnub.stop()

if __name__ == "__main__":
    main()
```