Skip to content

Commit 4fbb827

Browse files
fix(assets): send correct Content-Type for update and replace (v1.10.1)
Asset.update() forced Content-Type: multipart/form-data while sending a JSON body, and Asset.replace() set a bare multipart/form-data header (no boundary) while passing files=. Both made the CMA API reject the request with 422 'Please send a valid multipart/form-data payload', and both leaked the wrong Content-Type onto subsequent requests on the shared client. - update(): send the JSON body as application/json (matches the JS SDK and the live API, which returns 200) - replace(): let the HTTP layer build the multipart body with a proper boundary Bump version to 1.10.1 and update the asset update unit test accordingly.
1 parent a591837 commit 4fbb827

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# CHANGELOG
22

33
## Content Management SDK For Python
4+
---
5+
## v1.10.1
6+
7+
#### Date: 26 June 2026
8+
9+
- Fixed `Asset.update()` to send the JSON body with `Content-Type: application/json` instead of an invalid bare `multipart/form-data`, which the API rejected with 422.
10+
- Fixed `Asset.replace()` to let the HTTP layer set `multipart/form-data` with a proper boundary (a bare `multipart/form-data` header without a boundary previously caused a 422). Both fixes also remove a side effect that leaked the wrong `Content-Type` onto subsequent requests.
11+
412
---
513
## v1.10.0
614

contentstack_management/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def get_contentstack_endpoint(region='us', service='', omit_https=False):
102102
__author__ = 'dev-ex'
103103
__status__ = 'debug'
104104
__region__ = 'na'
105-
__version__ = '1.10.0'
105+
__version__ = '1.10.1'
106106
__host__ = 'api.contentstack.io'
107107
__protocol__ = 'https://'
108108
__api_version__ = 'v3'

contentstack_management/assets/assets.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ def replace(self, file_path):
174174
"""
175175

176176
url = f"assets/{self.asset_uid}"
177-
Parameter.add_header(self, "Content-Type", "multipart/form-data")
177+
# Let requests build the multipart body and set Content-Type WITH a boundary.
178+
# Setting a bare "multipart/form-data" (no boundary) makes the API reject the
179+
# upload with 422 "Please send a valid multipart/form-data payload".
180+
self.client.headers.pop("Content-Type", None)
178181
files = {"asset": open(f"{file_path}",'rb')}
179182
return self.client.put(url, headers = self.client.headers, params = self.params, files = files)
180183

@@ -407,7 +410,9 @@ def update(self, data):
407410
if self.asset_uid is None or '':
408411
raise Exception(ASSET_UID_REQUIRED)
409412
url = f"assets/{self.asset_uid}"
410-
Parameter.add_header(self, "Content-Type", "multipart/form-data")
413+
# Updating an asset's title/description sends a JSON body, so it must use
414+
# application/json. Forcing multipart/form-data here makes the API reject
415+
# the request with 422 "Please send a valid multipart/form-data payload".
411416
return self.client.put(url, headers = self.client.headers, params = self.params, data = data)
412417

413418
def publish(self, data):

tests/unit/assets/test_assets_unit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ def test_update(self):
167167
response = self.client.stack(api_key).assets(asset_uid).update(data)
168168
self.assertEqual(response.request.url, f"{self.client.endpoint}assets/{asset_uid}")
169169
self.assertEqual(response.request.method, "PUT")
170-
self.assertEqual(response.request.headers["Content-Type"], "multipart/form-data")
170+
# Asset update sends a JSON body, so Content-Type must be application/json
171+
# (it previously forced multipart/form-data, which the API rejects).
172+
self.assertEqual(response.request.headers["Content-Type"], "application/json")
171173

172174
def test_publish(self):
173175
data = {

0 commit comments

Comments
 (0)