面试题答案
一键面试import asyncio
import aiohttp
async def fetch(session, url):
try:
async with session.get(url) as response:
response.raise_for_status()
return await response.json()
except aiohttp.ClientError as e:
print(f"HTTP请求出现异常: {e}")
async def main():
url = "替换为指定的URL"
async with aiohttp.ClientSession() as session:
result = await fetch(session, url)
if result:
print(result)
if __name__ == "__main__":
asyncio.run(main())