'Python Connecting to Pusher Client

I'm trying to connect to a pusher client

Following the example from https://github.com/ekulyk/PythonPusherClient

I tried using the following code:

import pusherclient
import logging

root = logging.getLogger()
root.setLevel(logging.INFO)
ch = logging.StreamHandler(sys.stdout)
root.addHandler(ch)

global pusher

def callback(*args, **kwargs):
    print("processing Args:", args)
    print("processing Kwargs:", kwargs)


def connect_handler(data):
    channel = pusher.subscribe('global')
    

pusher = pusherclient.Pusher(appkey)
pusher.connection.bind('pusher:connection_established', connect_handler)
pusher.connect()

while True:
    
    time.sleep(1)

However, the callback is returning the following error:

Connection: Message - {"event":"pusher:error","data":{"code":4001,"message":"App key ********* not in this cluster. Did you forget to specify the cluster?"}}
Connection: Received error 4001

Reading the documentation form pusherclient, I can't find any argument that is allowing me to specify the cluster.

How would I specify the cluster I want to connect to? Is there another library that would allow me to connect and listen to a pusher channel in python?



Solution 1:[1]

I can't find a way to specify the cluster in the module you're using however, the offical Pusher page lists Pysher as the recomended python community library (client).

This is a fork/continuation of the library you're using now, and it does have support for clusters. A link is below:

https://github.com/deepbrook/Pysher

To change the cluster you simply change your Pusher class initialisation to the below:

pusher = pysher.Pusher(appkey, cluster="<cluser_name>")

Below is the link to the Pusher page on clusters, incase you also need to know the name of your cluster:

https://pusher.com/docs/channels/miscellaneous/clusters/#on-the-server-side

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman