TornadoTornadoTwistedAsyncioNativePythonPython-Tornado V4 SDK Troubleshooting Guide

 

These docs are for PubNub 4.0 for Python-Tornado V4 which is our latest and greatest! For the docs of the older versions of the SDK, please check PubNub 3.0 for Python, PubNub 3.0 for Python-Tornado and PubNub 3.0 for Python-Twisted.

If you have questions about the PubNub for Python SDK, please contact us at support@pubnub.com.

import pubnub
import logging

pubnub.set_stream_logger('pubnub', logging.DEBUG)
from pubnub import PubNubTornado

PubNubTornado.SDK_VERSION

In case of future() calls errors will be wrapped out by either TornadoEnvelope or PubNubTornadoException 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.
@gen.coroutine
def publish_future():
	e = yield 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))

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:

@gen.coroutine
def publish_result():
    try:
        result = yield 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)