最近我因为无法在asyncio循环中使用requests而转换成了aiohttp。
转换很完美,一切都很好,除了一个问题:我的控制台充满了
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时都会丢失
有没有办法修复此错误或隐藏它?
data = await resp.json(content_type=resp.content_type)
。但不确定是否正确。 - 555Russichcontent_type=None
相同。 - Andrew Svetlov