执行fetch(url)命令时出现Scrapy错误

eqoofvh9  于 2022-11-23  发布在  其他
关注(0)|答案(1)|浏览(237)

我在使用Scrapy执行fetch(url)命令时遇到了这个错误。我使用的是Scrapy 2.7.1,Python 3.10.6和Ubuntu 22.04上的miniconda
以下是我已完成的步骤:

scrapy startproject worldometers

cd worldometers

scrap shell

fetch("https://www.worldometers.info/world-population/population-by-country/")

这是我得到的错误消息:

File "/home/miniconda3/envs/main/lib/python3.10/site-packages/twisted/internet/defer.py", line 857, in _runCallbacks
    current.result = callback(  # type: ignore[misc]
  File "/home/miniconda3/envs/main/lib/python3.10/site-packages/scrapy/utils/defer.py", line 285, in f
    return deferred_from_coro(coro_f(*coro_args, **coro_kwargs))
  File "/home/miniconda3/envs/main/lib/python3.10/site-packages/scrapy/utils/defer.py", line 272, in deferred_from_coro
    event_loop = get_asyncio_event_loop_policy().get_event_loop()
  File "/home/miniconda3/envs/main/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-1 (start)'.
2022-11-12 21:08:55 [py.warnings] WARNING: /home/miniconda3/envs/main/lib/python3.10/site-packages/twisted/internet/defer.py:857: RuntimeWarning: coroutine 'SpiderMiddlewareManager.scrape_response.<locals>.process_callback_output' was never awaited
  current.result = callback(  # type: ignore[misc]

有任何修正错误的建议吗?
目前卡住了,我试着搜索互联网,但仍然没有解决方案

2fjabf4q

2fjabf4q1#

通过在项目的文件www.example.com中注解以下代码行解决了这个问题settings.py:

# Set settings whose default value is deprecated to a future-proof value
REQUEST_FINGERPRINTER_IMPLEMENTATION = '2.7'
#TWISTED_REACTOR = 'twisted.internet.asyncioreactor.AsyncioSelectorReactor'

相关问题