我想在没有 Web 服务器的情况下从本地主机异步获取文件。似乎可以使用 file:// 方案。以下代码示例取自文档,但显然它不起作用:
import aiohttp
import asyncio
async def fetch(session, url):
async with session.get(url) as response:
return await response.text()
async def main():
async with aiohttp.ClientSession() as session:
html = await fetch(session, 'file://localhost/Users/user/test.txt')
print(html)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
如何让它工作?
我看到的一种方法是使用 run_in_executor 在单独的线程池中使用“curl file://path”,但我认为应该有一种方法可以修复代码
犯罪嫌疑人X
相关分类