Nodriver:'NoneType'对象没有属性'close'

问题描述 投票:0回答:1

我正在学习nodriver(版本0.37)库https://ultrafunkamsterdam.github.io/nodriver/nodriver/quickstart.html

我的行动

python3.11 -m venv venv
source venv/bin/activate
pip install nodriver

我正在尝试这个代码

import nodriver as uc

async def main():

    browser = await uc.start()
    page = await browser.get('https://www.nowsecure.nl')


if __name__ == '__main__':
    uc.loop().run_until_complete(main())

错误

python main.py      
Traceback (most recent call last):
  File "/Users/mascai/root_folder/dev/projects/54_nodriver/main.py", line 11, in <module>
    uc.loop().run_until_complete(main())
  File "/opt/homebrew/Cellar/[email protected]/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/mascai/root_folder/dev/projects/54_nodriver/main.py", line 5, in main
    browser = await uc.start()
              ^^^^^^^^^^^^^^^^
  File "/Users/mascai/root_folder/dev/projects/54_nodriver/venv/lib/python3.11/site-packages/nodriver/core/util.py", line 96, in start
    return await Browser.create(config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mascai/root_folder/dev/projects/54_nodriver/venv/lib/python3.11/site-packages/nodriver/core/browser.py", line 91, in create
    await instance.start()
  File "/Users/mascai/root_folder/dev/projects/54_nodriver/venv/lib/python3.11/site-packages/nodriver/core/browser.py", line 394, in start
    await self.connection.send(cdp.target.set_discover_targets(discover=True))
  File "/Users/mascai/root_folder/dev/projects/54_nodriver/venv/lib/python3.11/site-packages/nodriver/core/connection.py", line 412, in send
    if not self.websocket or self.closed:
                             ^^^^^^^^^^^
  File "/Users/mascai/root_folder/dev/projects/54_nodriver/venv/lib/python3.11/site-packages/nodriver/core/connection.py", line 368, in __getattr__
    return getattr(self.target, item)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'closed'
successfully removed temp profile /var/folders/t6/7jk0v3817zb2_xfb6bf0vxpc0000gn/T/uc_tedc5epz
python nodriver
1个回答
0
投票

对我有用的是将 websockets 从 14.0 降低到

websockets==13.1
nodriver==0.37

© www.soinside.com 2019 - 2024. All rights reserved.