2

So, I'm creating a websocket client in python, this is the code

import websockets

ws = websockets.connect('ws://localhost:6789')

ws.send('asdf')

but whenever I tried to run it, it says

Traceback (most recent call last):
  File "client.py", line 5, in <module>
    ws.send('asdf')
AttributeError: 'Connect' object has no attribute 'send'

1 Answer 1

3

The object you have is the connector object which should be connected, similar to having a file descriptor that you need to open or use the "with" syntax. try:

import websockets

async with websockets.connect('ws://localhost:6789') as ws:
    await ws.send('asdf')
Sign up to request clarification or add additional context in comments.

1 Comment

ok will try later

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.