meraki / dashboard-api-python

Official Dashboard API library (SDK) for Python
MIT License
287 stars 149 forks source link

Library crashes with AttributeError when API returns 404 with no body #229

Closed ollipa closed 10 months ago

ollipa commented 10 months ago

Describe how you confirmed the issue is with the library, and not with the API itself, or a server-side issue of some other kind. Error originates from the library.

Python version installed Python 3.10

Meraki library version installed 1.38.0

Have you reproduced the issue with the latest version of this library? And with the latest version of Python? I can reproduce the error with the latest library version.

Describe the bug When Dashboard API returns 404 status (or any other status) with no body, the library doesn't handle the response well and crashes with AttributeError: 'NoneType' object has no attribute 'keys'.

How can we replicate the problem you're reporting? Call AsyncDashboardAPI.organizations.getOrganizationNetworks with a non-existing organization id.

Expected behavior The library should return APIError but it crashes instead an returns AttributeError: 'NoneType' object has no attribute 'keys'.

Additional context The problem seems to be here: https://github.com/meraki/dashboard-api-python/blob/7dd5f57c80636e1e0a04c48c32a88c840fc0a337/meraki/aio/rest_session.py#L242-L243

Aiohttp response.json returns None if the response body is empty and then the library sets message_is_dict incorrectly to True.

TKIPisalegacycipher commented 10 months ago

@ollipa thanks for reporting this. The fix is merged and will be included in a future release of the library. Feel free to rebase on this current main branch if you like.