PubNub LogoDocs
SupportContact SalesLoginTry Our APIs

›asyncio

asyncio

  • Getting Started
  • API Reference

    • Configuration
    • Publish & Subscribe
    • Presence
    • Access Manager
    • Channel Groups
    • Message Persistence
    • Mobile Push
    • Files
    • Message Actions
    • Miscellaneous
  • Status Events
  • Troubleshooting
  • Change Log
  • Feature Support
  • Platform Support
  • Reconnection Policies

Troubleshooting PubNub Python-asyncio SDK

Python version support

Python SDK versions 5.0.0 and higher no longer support Python v2.7 and the Twisted and Tornado frameworks. If you require support for any of these, use SDK version 4.8.1.

Note that PubNub will stop supporting versions of Python lower than 3.7 by the end of 2021.

How to enable logging

Use this code to enable logging:

import pubnub
import logging

pubnub.set_stream_logger('pubnub', logging.DEBUG)

How to find the version of your SDK

You can access your SDK version via constant:

from pubnub import PubNubAsyncio
PubNubAsyncio.SDK_VERSION

Error handling with future()

In case of future() calls errors will be wrapped out by either AsyncioEnvelope or PubNubAsyncioException which both implement two object fields:

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

future() usage:

async def publish_future():
    e = await pubnub.publish().channel("my_channel").message("hello!").future()
    if e.is_error():
        print("Error %s" % str(e))
        print("Error category #%d" % e.status.category)
        return
    else:
        print(str(e.result))

Error handling with result()

result() calls will return you just a result of the request without any state information. Errors should be caught using try/except blocks. For server-side errors a e.status field is populated to provide you more information about the request:

async def publish_result():
    try:
        result = await pubnub.publish().channel("my_channel").message("hello!").result()
        print(str(result))
    except PubNubException as e:
        print("Error %s" % str(e))
        if e.status is not None:
            print("Error category #%d" % e.status.category)
← Status EventsChange Log →
  • How to enable logging
  • How to find the version of your SDK
  • Error handling with future()
  • Error handling with result()
© PubNub Inc. - Privacy Policy