You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The RESTStream implementation assumes that request and response bodies are JSON. This is a reasonable default, but it currently makes it harder than it should it be to override these assumptions for other types of APIs, like ones based on XML.
We hardcode the json= parameter common across many of requests APIs here:
ifnotdataandjsonisnotNone:
# urllib3 requires a bytes-like body. Python 2's json.dumps# provides this natively, but Python 3 gives a Unicode string.content_type="application/json"try:
body=complexjson.dumps(json, allow_nan=False)
exceptValueErrorasve:
raiseInvalidJSONError(ve, request=self)
ifnotisinstance(body, bytes):
body=body.encode("utf-8")
and here
# Add content-type if it wasn't explicitly provided.ifcontent_typeand ("content-type"notinself.headers):
self.headers["Content-Type"] =content_type
it's clear that the same default behavior can be achieved by instead using the data= parameter and serializing the JSON payload ourselves. We might also be able to do this in a non-breaking way.
Feature scope
Taps (catalog, state, tests, etc.)
Description
The
RESTStream
implementation assumes that request and response bodies are JSON. This is a reasonable default, but it currently makes it harder than it should it be to override these assumptions for other types of APIs, like ones based on XML.We hardcode the
json=
parameter common across many ofrequests
APIs here:sdk/singer_sdk/streams/rest.py
Lines 378 to 384 in 72c9a19
By looking at the
requests
source1, hereand here
it's clear that the same default behavior can be achieved by instead using the
data=
parameter and serializing the JSON payload ourselves. We might also be able to do this in a non-breaking way.Footnotes
https://requests.readthedocs.io/en/latest/_modules/requests/models/#PreparedRequest.prepare_body ↩
The text was updated successfully, but these errors were encountered: