【发布时间】:2018-10-23 02:14:16
【问题描述】:
我使用aiohttp请求我的url,但是不知道为什么会出现这个错误!!!!!
async def get_location_data(url):
try:
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
data = await response.json()
return data
except Exception:
return None
当我收到响应并想更改列表中的项目时,会发生此错误:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-4: ordinal not in range(128)
搜了这么多,有人说应该用response.text(encoding="utf-8) 或者response.json(encoding="utf-8)
我该如何解决这个错误?
【问题讨论】:
-
堆栈跟踪会很有用
标签: encoding python-asyncio python-unicode unicode-string aiohttp