Skip to content

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

Description

@ollipa

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:

message = await response.json(content_type = None)
message_is_dict = True

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions