justpy icon indicating copy to clipboard operation
justpy copied to clipboard

AttributeError: module 'websockets' has no attribute 'legacy'

Open jasonjurotich opened this issue 4 years ago • 4 comments

I am getting the following error when I run a justpy script. I am on a Macbook Air M1, using pyenv and python 3.9.5. Everything in theory is up to date. Going into the Browser it constantly says: Page needs to be reloaded, click OK to reload and each time you click on OK, the error below comes out. It will do the same in any virtual environment that I have active. Please let me know if I should send any logs on this. It appears to be a problem with uvicorn. Thanks.

JustPy ready to go on http://127.0.0.1:8000

WARNING server: Error in opening handshake Traceback (most recent call last): File "/Users/jj/.pyenv/versions/3.9.5/lib/python3.9/site-packages/websockets/server.py", line 130, in handler path = await self.handshake( File "/Users/jj/.pyenv/versions/3.9.5/lib/python3.9/site-packages/websockets/server.py", line 532, in handshake early_response = await early_response_awaitable File "/Users/jj/.pyenv/versions/3.9.5/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 104, in process_request websockets.legacy.handshake.check_request(headers) AttributeError: module 'websockets' has no attribute 'legacy'

jasonjurotich avatar Jun 20 '21 16:06 jasonjurotich

I am not sure, but I think this is caused by the new version (version 9) of the websockets package that unicorn depends on. Could you please try running this with version 8 of websockets?

elimintz avatar Jun 20 '21 17:06 elimintz

OK, so... turns out that the problem was precisely that websockets was at 8.1 ! It would not go higher because it was depending on pyppeteer. I uninstalled both websockets and pyppeteer and force installed websockets 9.1 and then it worked!! Hopefully this will help someone else in the future. Thanks for responding and at least putting me in the right direction. (You can close the issue if you wish.) Take care.

jasonjurotich avatar Jun 21 '21 00:06 jasonjurotich

So as @jasonjurotich mentioned, running with websockets 9.1 solved the issue for me ! Thank you !

Abraham-Dev-India avatar Jul 06 '21 18:07 Abraham-Dev-India

When WebSockets 9.1 was installed, the issue was solved. Thank you, @jasonjurotich!

yiyi-ll avatar Nov 18 '21 08:11 yiyi-ll