1

For this problem (stackoverflow.com/questions/4086435/), I tried to make a Python 3 version of the library python-websocket (github.com/mtah/python-websocket/), here is my code: https://gist.github.com/663175.

Blender comes with his own Python 3.1 package, so I added my file directly in its «site-packages» folder. I get this error now:

Traceback (most recent call last):
  File "websocket.py", line 6, in 
AttributeError: 'module' object has no attribute 'WebSocket'

when running this code in Blender:


import sys, os, asyncore, websocket

def msg_handler(msg): print(msg)

socket = websocket.WebSocket('ws://localhost:8080/', onmessage=msg_handler) socket.onopen = lambda: socket.send('Hello world!')

try: asyncore.loop() except KeyboardInterrupt: socket.close()

I found that a __init__.py is needed so I added but it didn't help… What I am doing wrong here ? Thanks for your help.

1 Answer 1

3

It looks like you called your script websocket.py, so the import of websocket finds the script itself, instead of the installed module by that name. Rename the script to something else (and if it created a websocket.pyc file, delete that.)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your reply, I renamed the script python-websocket.py but I have the same error. There was no websocket.pyc.
Ok, sorry… It works, I misunderstood what you said. Thanks again !

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.