Skip to content

Request content-type persistence causes 420 error on some requests #323

@jeremyist

Description

@jeremyist

On the following lines of code, content-type is set in the http client's _header field during json requests. This causes subsequent requests to break if they rely on a different content-type. For instance, if you call create_application (json data) followed by update_number (form data) using the same Vonage client, it appears to force it to use application/json for the update number call, causing a 420 error.

https://github.com/Vonage/vonage-python-sdk/blob/54fa90ddd0508e52f87c9baa775143afc73cb5d9/http_client/src/vonage_http_client/http_client.py#L264C9-L277

Expected Behavior

The content-type header should be set only for the currently running request

Current Behavior

The content-type header appears to be sticky, and forces incorrect headers on subsequent requests.

Possible Solution

Steps to Reproduce (for bugs)

  1. Initialize the vonage client and attempt to use it for 2 requests with different content-types (example: create_application then update_number)

Context

We were debugging an issue with a project that was throwing 420s and was difficult to reproduce. Postman requests, curl requests, etc all worked, but our app failed. The issue was we call a few endpoints in a row when a number is being assigned. Currently we worked around this by re-initializing the client each time.

Your Environment

  • Version used: 4.5, 4.4

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