Ghbgon Gon
Ghbgon Gon

Reputation: 11

Module 'websockets' has no attribute 'client'

I am running, in Jupyter Notebook with Anaconda Navigator, a code in python that uses the "requests_html" library, and this error has occurred: "AttributeError: module 'websockets' has no attribute 'client'" I already have installed the websocks-client package, but still occurs.

from requests_html import AsyncHTMLSession
asession = AsyncHTMLSession()

r = await asession.get('https://python.org/')
await r.html.arender(timeout=15)
resp = r.html.raw_html
print(resp)

Upvotes: 1

Views: 6210

Answers (4)

Mwongera808
Mwongera808

Reputation: 889

I had to downgrade to websockets 8.1

pip install websockets==8.1

Worked afterwards.

Upvotes: 1

Sergei
Sergei

Reputation: 21

If nothing else works, try to delete "websocket" folder from "python/site-packages/" folder.

When I did it, my IDE (PyCharm) asked me if I want to install package "websocket", then "websocket-client" and after I clicked "yes" downloaded them automatically.

Upvotes: 0

Jim
Jim

Reputation: 31

Explicitly importing the 'client' before running my code fixed this issue for me (I did not test code given in original post).

from websockets import client

Upvotes: 3

Teddy Katayama
Teddy Katayama

Reputation: 138

This was patched in the latest version of pyppeteer, make sure you have the latest version. There is a pull request that hasn't been merged yet to allow support for websockets 10. If you simply install the latest version of pyppeteer, then you will be left with websockets 9. I need websockets 10 for other modules so I installed pyppeteer using the following command and this fixed the requests_html error.

pip install -U git+https://github.com/pyppeteer/pyppeteer@dev

Upvotes: 1

Related Questions