Bug in AIO SDK for generateDeviceCameraSnapshot?

PhilipDAth
Kind of a big deal
Kind of a big deal

Bug in AIO SDK for generateDeviceCameraSnapshot?

This sample code works (environment has API key):

import meraki

def main():
    dashboard=meraki.DashboardAPI(print_console=False)
    response = dashboard.camera.generateDeviceCameraSnapshot("xxxx-xxxx-xxxx")
    print(response)

if __name__ == "__main__":
    main()

This AIO version does not:

import meraki.aio,asyncio

async def main():
	async with meraki.aio.AsyncDashboardAPI(print_console=False) as aiomeraki:
		response = await aiomeraki.camera.generateDeviceCameraSnapshot("xxxx-xxxx-xxxx")
		print(response)


if __name__ == "__main__":
	# Execute only if run as a script
	asyncio.run(main())

It produces the error:

Error:
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/json;charset=utf-8', url=URL('https://api.meraki.com/api/v1/devices/xxxx-xxxx-xxxx/camera/generateSnapshot')

 

 

Bug?

9 Replies 9
PhilipDAth
Kind of a big deal
Kind of a big deal

python -V
Python 3.8.10

pip show meraki
Name: meraki
Version: 1.12.0
Summary: Cisco Meraki Dashboard API library
Home-page: https://github.com/meraki/dashboard-api-python
Author: Cisco Meraki
Author-email: api-feedback@meraki.net
License: MIT
Location: /home/ubuntu/.local/lib/python3.8/site-packages
Requires: requests, aiohttp
Required-by: 
PhilipDAth
Kind of a big deal
Kind of a big deal

Just thinking about this further, it mentions the type "text/json".  That's wrong.  It should be "application/json".

 

PhilipDAth
Kind of a big deal
Kind of a big deal

If I change "lib/python3.8/site-packages/meraki/aio/rest_session.py", line 410, from:

return await response.json()

to:

return await response.json(content_type=None)

it works.

 

I think the problem is the API itself is returning the wrong content type, and that the standard Merkai library doesn't check the content type so this error is not showing up.

Greenberet
Head in the Cloud

I've just checked this and the issue is the type checking in aiohttp. There isn't any type checking in the request based library. That's why it is working here.

 

response.json() is checking, if the content-type is "application/json". For an odd reason in this endpoint the dashboard will return "text/json"

 

as a workaround I would disable type-checking:

 

change

meraki.aio.rest_session.py:Line 470

 

 

            return await response.json()

 

 

to

 

 

            return await response.json(content_type=None)

 

 

 

@John_on_API 

In my opinion this is a bug in the endpoint on dashboard itself. Why is this the only (as far as we know yet) endpoint with content-type "text/json" instead of "application/json".
I could make a fix on the client and override the check in aiohttp for "text/json", but that would be a workaround which shouldn't be needed.
Edit: as posted below "text/json" isn't a correct mime type, so it should really be fixed on the endpoint


/Edit:

@PhilipDAth  I'm glad that you came to the same conclusion as I =D

You've just posted yours while I was writing on my reply ^^

Greenberet
Head in the Cloud

According to IANA the correct mime type is "application/json" and "text/json" is completely wrong.
I've opened a support case for this: 07059259

PhilipDAth
Kind of a big deal
Kind of a big deal

@John_on_API , could we drag you into this one?  It's a minor bug in an API response.

John_on_API
Meraki Employee
Meraki Employee

Thanks @Greenberet, I agree that is a bug and hopefully a trivial fix. I expect the support team will take it from here for escalation to eng.

Greenberet
Head in the Cloud

Supportupdate (~45 minutes ago)

Our development team are still working on getting this resolved. Thank you for your patience so far.
Greenberet
Head in the Cloud

@John_on_APIcan you push this internally a little bit more? The case is still open and the last update was from today:

 


I'm afraid there haven't been any further updates from our engineering team on this one. I appreciate this has been open some time, hopefully they will resolve this soon.
Get notified when there are additional replies to this discussion.