PagerDuty / pdpyras

Low-level PagerDuty REST/Events API client for Python
MIT License
129 stars 29 forks source link

rput raises PDHTTPError from JSONDecodeError when adding a user to a team #86

Closed mpjura closed 2 years ago

mpjura commented 2 years ago

Adding a user to a team with client.rput(f'teams/{team}/users/{user}') raises PDHTTPError from JSONDecodeError encountered trying to decode response text. The raw response from put is a 204 with no content.

Removing a user from a team with client.rdelete(f'teams/{team}/users/{user}') does not raise the same error even though the raw response is also a 204 with no content.

Deconstrained commented 2 years ago

Hi @mpjura,

The r* methods assume that the endpoint they are used on has entity wrapping. That does not apply in the case of this endpoint.

One can get around the issue by simply using put instead of rput.

See also: https://pagerduty.github.io/pdpyras/#list-of-non-conformal-endpoints

(Side note: The rdelete method works in this case because it's built around an otherwise universal convention in DELETE endpoints; the expected response is 204 / no content. Endpoints that have wrapped entities however should always respond with JSON to PUT requests.)

mpjura commented 2 years ago

got it, thanks @Deconstrained