Giter VIP home page Giter VIP logo

python-actioncable-zwei's People

Contributors

0x7466 avatar brandonsturgeon avatar lionelnicolas avatar pj-parthjoshi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

python-actioncable-zwei's Issues

Cant suscribe to Channels, get stuck in 'pending' state

Hi! Iḿ having a similar problem, i get connected to my localhost server but my subscription is stuck at pennding state, so i do not recieve any messages nor can send them.

from actioncable.connection import Connection
from actioncable.subscription import Subscription

connection = Connection(url='ws://localhost:3000/cable', origin='http://localhost:3000')
connection.connect()
sleep(3)
print(connection.connected) #this is True
subscription = Subscription(connection, identifier={'channel': 'RaspiCommChannel'})
subscription.create()

If I check subscription state is 'pending' allways.
I try it from python console, using Python 3.7.2.
Can you help me please? Thanks!

Originally posted by @eterrones in #4 (comment)

Unable to send cookie using ActionCableZwei

Using:

  • Python 2.7.12
  • Rails 5.1.2
  • Ruby 2.4.1

I am using ActionCable on webpage which works fine in rails, now trying to connect from python using https://github.com/tobiasfeistmantl/python-actioncable-zwei ActionCableZwei - A Python 3 client for Rails' Action Cable

Below line connects successfully:
connection = Connection(url='ws://localhost:4000/cable', origin='http://localhost:4000/')

and I get proper logs in rails.

Now, I want to send cookies with sockets but Below line is unable to connect nor do I get any logs in rails.
connection = Connection(url='ws://localhost:4000/cable', origin='http://localhost:4000/', log_ping=False, cookie=coo)

Also tried using log_ping to True/False

Below is full code that am trying:

from actioncable.connection import Connection
from actioncable.subscription import Subscription
from actioncable.message import Message
import datetime
import random
from time import sleep
import Cookie 

coo = Cookie.SimpleCookie()
coo["fig"] = "newton"
coo["sugar"] = "wafer"

# connection = Connection(url='ws://localhost:4000/cable', origin='http://localhost:4000/')
connection = Connection(url='ws://localhost:4000/cable', origin='http://localhost:4000/', cookie=coo)
connection.connect()

subscription = Subscription(connection, identifier={'channel': 'TestChannel'})
subscription.create()

sleep(30)

subscription.remove()
connection.disconnect()

I just don't get any ping/log in rails about trying to connect. How can I fix this?

Can't seem to work because of error on callbacks

Hello.

I tried to test the example, but it didn't work and I found out why.

There were mismatching parameters because of the self in the callback. So I made a small change: I changed the callbacks for lambdas to avoid the conflict with self

diff --git a/actioncable/connection.py b/actioncable/connection.py
index 1190696..08c6507 100644
--- a/actioncable/connection.py
+++ b/actioncable/connection.py
@@ -85,9 +85,9 @@ class Connection:
                     self.url,
                     cookie=self.cookie,
                     header=self.header,
-                    on_message=self._on_message,
-                    on_close=self._on_close)
-                self.websocket.on_open = self._on_open
+                    on_message=lambda socket, message : self._on_message(socket, message),
+                    on_close=lambda socket : self._on_close(socket))
+                self.websocket.on_open = lambda socket : self._on_open(socket)
 
                 self.websocket.run_forever(ping_interval=5, ping_timeout=3, origin=self.origin)
                 time.sleep(2)

I hope this helps

Channels stuck in a 'pending' state

I'm occasionally seeing messages "Connection not established. Add message to queue.", which is based off the channel still being in a 'pending' state, meaning the code never received a 'subscribed' message from the server.

BUT I am seeing the ActionCable server did send that subscribed message! I'm not sure why py-actioncable isn't receiving this subscribed message, and therefore pulling the channel out of 'pending'.

I see this issue locally and when talking to a dockerized server. I'd love to provide sample code, but it's a little hard to reproduce. This dance works flawlessly the first time, and generally happens when there is an unhealthy connection ping, and py-actioncable attempts to reconnect.

Do you get this issue as well sometimes?

Callback reference missing in Subscription example

When I use the Subscription example verbatim, the callback variable is missing, giving an error.
Expected: Connection to URL specified, and an attempt to subscribe to named channel.

Example code:

from actioncable.connection import Connection
from actioncable.subscription import Subscription

connection = Connection(url='ws://localhost:3000/cable', origin='http://localhost:3000')
connection.connect()

subscription = Subscription(connection, channel_name='AppChannel', identifier={'additional': 'params'})  # You don't have to provide the channel name in the identifier param.

def on_receive(message):
  print('New message arrived!')
  print('Action: {} | Data: {}'.format(message.action, message.data))

subscription.on_receive(callback)
subscription.create()

ModuleNotFoundError in examples

Following the README verbatim, and pasting in the examples, I'm getting an error finding the modules. I'm new to Python, but something seems off.

Traceback (most recent call last): File "./actioncable.py", line 1, in <module> from actioncable.subscription import Subscription File "/Users/nic/programming/test_python/actioncable.py", line 1, in <module> from actioncable.subscription import Subscription ModuleNotFoundError: No module named 'actioncable.subscription'; 'actioncable' is not a package

Also: Thanks for writing this! I lost the entire morning thinking that ActionCable was so great, only to realize that as always, it only works well inside a Rails world where all the parameters are abstracted away. :(

Outdated README/version number

I'm still getting the hang of github, so I apologize if posting this as an issue is breaking etiquette or if I am supposed to mention it another way?
This package is very useful, but unfortunately the readme hurts more than it helps.

  • using pip install will install an older version that does not have the December 2019 changes (so it will not work). changing the instruction to pip install git+https.... would fix it easily, but I don't know if the owner wants to update Pypi as well
  • the version number on Pypi is identical to the version number in this repo's setup.py (which makes the first issue more difficult to figure out)
  • in my uses, Message objects from ActionCable were structured in a way that has no 'action' and 'data' properties. I don't know if this is specific to the site I was contacting, but readme template for the on_receive callback function would not work until I realized that and removed them.

Running example code does not connect to server

When I copy the examples and run them, nothing happens. Meaning, my rails server shows no connection. I know the URL to be correct

Using the example Connect code

  from actioncable.connection import Connection
   from actioncable.subscription import Subscription
   
   connection = Connection(url='ws://localhost:3000/cable', origin='http://localhost:3000')
   connection.connect()
   

When I run this, the rails server shows no new connections

Puma starting in single mode...
* Version 3.8.2 (ruby 2.3.0-p0), codename: Sassy Salamander
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.