18910140161

python模块有哪些:Python-模块'WebSockets'没有属性'客户'-堆栈溢出

顺晟科技

2022-10-18 13:37:27

241

我使用Anaconda Navigator在Jupyter Notebook中运行一个Python代码,该代码使用“请求”_“ HTML ”。库,并且发生了以下错误:";AttributeError:模块' WebSockets '没有属性' Client '";我已经安装了websocks-client包,但仍然发生。

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)

顺晟科技:

这是在Pyppeteer的最新版本中修补的,请确保您拥有最新版本。有一个Pull请求尚未合并,以允许支持websockets 10。如果您只是安装了最新版本的Pyppeteer,那么您将只剩下websockets 9。对于其他模块,我需要websockets 10,因此我使用以下命令安装了Pyppeteer,这修复了requests_html错误。

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

如果没有其他工作,尝试删除";WebSocket";来自";python/site-packages/";的文件夹文件夹.

当我这样做的时候,我的IDE(PyCharm)问我是否要安装包";WebSocket";,然后";WebSocket-Client"在我点击“是”之后已自动下载.

在运行我的代码之前

显式导入“客户端”为我解决了这个问题(我没有测试原始帖子中给出的代码)。

从WebSockets导入客户端

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航