1

I am trying to make a basic connection to PubNub and get some basic output with python. When I run the files in bash on windows I am getting a 504 error. I checked Pubnub and it says I am getting some usage which is strange. I am using pubnub 4.1.6

Any help with this would be much appreciated

Thank you so much for your help in advance

Please see the image to see the code I run and the error I am getting.

:Code i run in bash and outcome of running code

import time
from pubnub.pubnub import PubNub
from pubnub.pnconfiguration import PNConfiguration
from pubnub.callbacks import SubscribeCallback




pnconfig = PNConfiguration()
#pnconfig.ssl = True

pnconfig.subscribe_key = subscribe_key = 'XXX'
pnconfig.publish_key = publish_key ='XXX'

pubnub = PubNub(pnconfig)

'''Test Channel global variable'''
TEST_CHANNEL = 'TEST_CHANNEL'

pubnub.subscribe().channels([TEST_CHANNEL]).execute()

'''
Listen class extends SubscribeCallback and herits its behaviour
Must be put into a class as it's equipped to handle the different events that occur in this channel 
'''
class Listener(SubscribeCallback):
   def message(self, pubnub, message_object):
       print(f'\n-- Incoming message object: {message_object}')

'''Instansiate an instance of message class within a call to add listener'''
pubnub.add_listener(Listener())


def main():
    '''Sleep to ensure subsribe runs runs'''
    time.sleep(1)

    pubnub.publish().channel(TEST_CHANNEL).message({'foo': 'bar'}).sync()

if __name__=='main':
    main()


KeithNolo
  • 145
  • 2
  • 14
  • 1
    Please try this after you uncomment `#pnconfig.ssl = True`. TLS (formerly known as SSL) can prevent these sorts of issues that cant stem from *ISP traffic shaping*. Let me know if that changes anything for you. – Craig Conover Feb 02 '20 at 16:27
  • Just curious if you had any success with the above suggestion. – Craig Conover Feb 06 '20 at 06:42
  • Hi Craig, I tried what you suggested but it didn't help. I got it working in the end. It seemed to not like the main method for some reason, because when I took it out it worked. Really strange, thanks for your help by the way. – KeithNolo Feb 07 '20 at 09:55
  • That is odd. Would love to know root cause so if you do find out post it up here as an answer. But happy you got it resolved. In future you can ping PubNub Support directly but we monitor StackOverflow very closely. – Craig Conover Feb 07 '20 at 15:24

0 Answers0