Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ nylas-python Changelog
======================
Unreleased
----------
* Fix draft and other JSON API requests failing with "only JSON and multipart supported" by sending `Content-Type: application/json` instead of `application/json; charset=utf-8`

v6.15.0
----------
Expand Down
2 changes: 1 addition & 1 deletion nylas/handler/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,6 @@ def _build_headers(
if data is not None and data.content_type is not None:
headers["Content-type"] = data.content_type
elif response_body is not None:
headers["Content-type"] = "application/json; charset=utf-8"
headers["Content-type"] = "application/json"

return {**headers, **extra_headers, **override_headers}
15 changes: 8 additions & 7 deletions tests/handler/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_build_headers_json_body(self, http_client, patched_version_and_sys):
"X-Nylas-API-Wrapper": "python",
"User-Agent": "Nylas Python SDK 2.0.0 - 1.2.3",
"Authorization": "Bearer test-key",
"Content-type": "application/json; charset=utf-8",
"Content-type": "application/json",
}

def test_build_headers_form_body(self, http_client, patched_version_and_sys):
Expand Down Expand Up @@ -200,7 +200,7 @@ def test_execute_download_request_override_timeout(
"X-Nylas-API-Wrapper": "python",
"User-Agent": "Nylas Python SDK 2.0.0 - 1.2.3",
"Authorization": "Bearer test-key",
"Content-type": "application/json; charset=utf-8",
"Content-type": "application/json",
},
timeout=60,
stream=False,
Expand Down Expand Up @@ -299,7 +299,7 @@ def test_execute(self, http_client, patched_version_and_sys, patched_request):
"X-Nylas-API-Wrapper": "python",
"User-Agent": "Nylas Python SDK 2.0.0 - 1.2.3",
"Authorization": "Bearer test-key",
"Content-type": "application/json; charset=utf-8",
"Content-type": "application/json",
"test": "header",
},
data=b'{"foo": "bar"}',
Expand Down Expand Up @@ -332,7 +332,7 @@ def test_execute_with_serialized_json_body(
"X-Nylas-API-Wrapper": "python",
"User-Agent": "Nylas Python SDK 2.0.0 - 1.2.3",
"Authorization": "Bearer test-key",
"Content-type": "application/json; charset=utf-8",
"Content-type": "application/json",
},
data=canonical,
timeout=30,
Expand All @@ -347,7 +347,7 @@ def test_build_request_sets_content_type_for_serialized_json_body(
request_body=None,
serialized_json_body=b"{}",
)
assert request["headers"]["Content-type"] == "application/json; charset=utf-8"
assert request["headers"]["Content-type"] == "application/json"

def test_execute_override_timeout(
self, http_client, patched_version_and_sys, patched_request
Expand Down Expand Up @@ -376,7 +376,7 @@ def test_execute_override_timeout(
"X-Nylas-API-Wrapper": "python",
"User-Agent": "Nylas Python SDK 2.0.0 - 1.2.3",
"Authorization": "Bearer test-key",
"Content-type": "application/json; charset=utf-8",
"Content-type": "application/json",
"test": "header",
},
data=b'{"foo": "bar"}',
Expand Down Expand Up @@ -466,7 +466,7 @@ def test_execute_with_headers(self, http_client, patched_version_and_sys, patche
"X-Nylas-API-Wrapper": "python",
"User-Agent": "Nylas Python SDK 2.0.0 - 1.2.3",
"Authorization": "Bearer test-key",
"Content-type": "application/json; charset=utf-8",
"Content-type": "application/json",
"test": "header",
},
data=b'{"foo": "bar"}',
Expand Down Expand Up @@ -497,6 +497,7 @@ def test_execute_with_utf8_characters(self, http_client, patched_version_and_sys
assert response_json == {"success": True}
# Verify that the data is sent as UTF-8 encoded bytes
call_kwargs = patched_request.call_args[1]
assert call_kwargs["headers"]["Content-type"] == "application/json"
assert "data" in call_kwargs
sent_data = call_kwargs["data"]

Expand Down
Loading