Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

运行到notes_res = await self.xhs_client.get_note_by_keyword的API请求时,RetryError #514

Closed
dannishushu opened this issue Dec 6, 2024 · 2 comments

Comments

@dannishushu
Copy link

dannishushu commented Dec 6, 2024

macOS 15.1.1
Python 3.13

使用的是qrcode扫码登录模式,代码可以打开浏览器,生成二维码,扫码后也可以登陆,但是运行到搜索笔记API时/api/sns/web/v1/search/notes,就会出现RetryError的错误

爬取类型是搜索关键字
CRAWLER_TYPE = (
"search" # 爬取类型,search(关键词搜索) | detail(帖子详情)| creator(创作者主页数据)
)

config中代理模式选择的False,关闭了 IP 代理
ENABLE_IP_PROXY = False

也关闭了无头模式
HEADLESS = False

现场log如下:

2024-12-06 11:29:16 MediaCrawler INFO (core.py:135) - [XiaoHongShuCrawler.search] search xhs keyword: 编程副业, page: 1
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/tenacity/asyncio/init.py", line 114, in call
result = await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/x/PycharmProjects/PythonProject/media_platform/xhs/client.py", line 100, in request
async with httpx.AsyncClient(proxies=self.proxies) as client:
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
TypeError: AsyncClient.init() got an unexpected keyword argument 'proxies'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py", line 1570, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/x/PycharmProjects/PythonProject/main.py", line 66, in
asyncio.get_event_loop().run_until_complete(main())
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 721, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
File "/Users/x/PycharmProjects/PythonProject/main.py", line 56, in main
await crawler.start()
File "/Users/x/PycharmProjects/PythonProject/media_platform/xhs/core.py", line 98, in start
await self.search()
File "/Users/x/PycharmProjects/PythonProject/media_platform/xhs/core.py", line 139, in search
notes_res = await self.xhs_client.get_note_by_keyword(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<8 lines>...
)
^
File "/Users/x/PycharmProjects/PythonProject/media_platform/xhs/client.py", line 233, in get_note_by_keyword
return await self.post(uri, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/x
/PycharmProjects/PythonProject/media_platform/xhs/client.py", line 151, in post
return await self.request(
^^^^^^^^^^^^^^^^^^^
...<5 lines>...
)
^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/tenacity/asyncio/init.py", line 189, in async_wrapped
return await copy(fn, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/tenacity/asyncio/init.py", line 111, in call
do = await self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/tenacity/asyncio/init.py", line 153, in iter
result = await action(retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/tenacity/_utils.py", line 99, in inner
return call(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/tenacity/init.py", line 419, in exc_check
raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x11344ae50 state=finished raised TypeError>]
Exception ignored in: <function _DeleteDummyThreadOnDel.del at 0x10455e3e0>
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_pep_669_tracing.py", line 555, in py_raise_callback
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/threading.py", line 1435, in current_thread
TypeError: 'NoneType' object is not subscriptable
Exception ignored in: <function _DeleteDummyThreadOnDel.del at 0x10455e3e0>
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_pep_669_tracing.py", line 555, in py_raise_callback
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/threading.py", line 1435, in current_thread
TypeError: 'NoneType' object is not subscriptable

Process finished with exit code 1

断点debug了很长时间也没有头绪,求助

@NanmiCoder
Copy link
Owner

错误出在了这里,httpx这个库正常情况下可以传递这个参数的,你看下是是不是httpx的版本不对。

TypeError: AsyncClient.init() got an unexpected keyword argument 'proxies'

@dannishushu
Copy link
Author

错误出在了这里,httpx这个库正常情况下可以传递这个参数的,你看下是是不是httpx的版本不对。

TypeError: AsyncClient.init() got an unexpected keyword argument 'proxies'

已解决,httpx 0.28.0会出现proxies参数的问题,回退至0.24.0就OK了,多谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants