【发布时间】:2018-02-17 10:33:06
【问题描述】:
我最近从 requests 切换到 aiohttp,因为我无法在 asyncio 循环中使用它。
交换进行得很顺利,除了一件事,一切都很顺利。我的控制台充满了
Attempt to decode JSON with unexpected mimetype:
和
Attempt to decode JSON with unexpected mimetype: txt/html; charset=utf-8
我的代码有一个站点列表,它也可以从中获取 JSON,每个站点都不同,但每个站点的循环基本相同,我在这里对其进行了简化:
PoolName = "http://website.com"
endpoint = "/api/stats"
headers = "headers = {'content-type': 'text/html'}" #Ive tried "application/json" and no headers
async with aiohttp.get(url=PoolName+endpoint, headers=headers) as hashrate:
hashrate = await hashrate.json()
endVariable = hashrate['GLRC']['HASH']
它运行良好,连接到站点抓取 json 并正确设置 endVariable。但由于某种原因
Attempt to decode JSON with unexpected mimetype:
在每次循环时打印。这很烦人,因为它将统计信息打印到控制台,并且每次抓取站点 json 时它们都会迷失在错误中
有没有办法修复或隐藏此错误?
【问题讨论】:
标签: python json python-3.x python-asyncio aiohttp