如何从 aiohttp 获得 json 响应?
How to get json response from aiohttp?
如何从 aiohttp 获得 json 响应?
如果我使用 .json() 我得到错误:
File "main.py", line 371, in _checker
user_name = f'{res_json["username"]}#{res_json["discriminator"]}'
TypeError: 'coroutine' 对象不可订阅
.json()
returns a coroutine, hence you need to await
the response.json()
to actually run the coroutine
async with session.get('https://api.github.com/events') as resp:
print(await resp.json())
^^^^^
如何从 aiohttp 获得 json 响应? 如果我使用 .json() 我得到错误:
File "main.py", line 371, in _checker user_name = f'{res_json["username"]}#{res_json["discriminator"]}'
TypeError: 'coroutine' 对象不可订阅
.json()
returns a coroutine, hence you need to await
the response.json()
to actually run the coroutine
async with session.get('https://api.github.com/events') as resp: print(await resp.json()) ^^^^^