pypijson95% confidence\u2191 42

Python - Attempt to decode JSON with unexpected mimetype:

Full error message
I recently swapped over from requests to aiohttp because I couldn't use it in asyncio loops.

The swap went perfectly and everything goes well except for one thing. My console is full of 

Attempt to decode JSON with unexpected mimetype:

and

Attempt to decode JSON with unexpected mimetype: txt/html; charset=utf-8

My code has a list of sites it goes too and grabs JSON from, Each site is different but my loop is basically the same for each of them, Ive simplified it here:

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']

It works perfectly, connects to the site grabs the json and sets endVariable correctly. but for some reason 

Attempt to decode JSON with unexpected mimetype:

prints every time it goes through the loop. Which is annoying because it prints stats to the console and they get lost in the the errors each time it grabs a sites json

Is there a way to fix this error or to hide it?

aiohttp is trying to do the right thing and warn you of incorrect Content-Type, which could at worst indicate that you are not getting JSON data at all, but something unrelated, such as the HTML content of an error page. However, in practice many servers are misconfigured to always send the incorrect MIME type in their JSON responses, and JavaScript libraries apparently don't care. If you know you're dealing with such a server, you can always silence the warning by invoking json.loads yourself: import json # ... async with self._session.get(uri, ...) as resp: data = await resp.read() hashrate = json.loads(data) Specifying Content-Type as you attempted makes no difference because it only affects the Content-Type of your request, whereas the problem lies in the Content-Type of the server's response, which is not under your control.

API access

Get this solution programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/error/50c71b8a6c85948f0f9f03c04f776e3b478cb4b56a4b5ba58ea2aa5c38b58ae9
hash \u00b7 50c71b8a6c85948f0f9f03c04f776e3b478cb4b56a4b5ba58ea2aa5c38b58ae9
Python - Attempt to decode JSON with unexpected mimetype: — DepScope fix | DepScope