AttributeError: module 'websockets' has no attribute 'legacy'
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'
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?
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.
So as @jasonjurotich mentioned, running with websockets 9.1 solved the issue for me ! Thank you !
When WebSockets 9.1 was installed, the issue was solved. Thank you, @jasonjurotich!