Troubleshooting PubNub Python 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 PubNub
PubNub.SDK_VERSION
Error handling with sync()
In case of sync()
calls errors will be wrapped out by either Envelope
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 usinge.is_error()
helper.
try:
e = pubnub.publish().channel("my_channel").message("hello!").sync()
print(str(e.result))
except PubNubException as e:
print("Error %s" % str(e))
if status is not None:
print("Error category #%d" % e.status.category)
Error handling with async()
async()
call lets you check for errors using status.is_error()
helper:
def callback(result, status):
if status.is_error():
print("Error %s" % str(status.error_data.exception))
print("Error category #%d" % status.category)
else:
print(str(result))