【发布时间】:2025-12-06 23:10:01
【问题描述】:
所以我设法让 asyncio / Google CSE API 一起工作......当我在 PyCharm 上运行我的代码时,我能够打印出我的结果。但是,在打印内容的最后是错误“TypeError: 'NoneType' object is not callable”。
我怀疑这与我的列表有关,也许循环试图搜索另一个词,即使我在列表的末尾...
另外..这是我的第一个问题帖子,因此请随时提供有关如何更好地提问的建议
想法?
searchterms = ['cheese',
'hippos',
'whales',
'beluga']
async def sendQueries(queries, deposit=list()):
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
loop = asyncio.get_event_loop()
futures = [
loop.run_in_executor(
executor,
searching(queries)
)
]
for response in await asyncio.gather(*futures):
deposit.append(response.json())
return deposit
def running():
loop = asyncio.get_event_loop()
loop.run_until_complete(loop.create_task(sendQueries(searchterms)))
loop.close()
print(running())
print(str(time.time() - x))
我的错误可以追溯到“for response in await asyncio.gather(*futures):”
供您参考,搜索(查询)只是我的 Google CSE API 调用的函数。
【问题讨论】:
-
无关:您应该阅读mutable default arguments。您可能会遇到
deposit的问题。
标签: python typeerror python-asyncio nonetype