Skip to content

Commit 398ae5c

Browse files
author
Sam Wierema
committed
Send all requests as JSON
This change mitigates an issue where nested parameters (such as typedetails) can be incorrectly processed by the requests library in Python.
1 parent f0a2604 commit 398ae5c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

messagebird/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
import json
23
import requests
34

45
try:
@@ -32,13 +33,14 @@ def request(self, path, params={}):
3233
headers = {
3334
'Accept' : 'application/json',
3435
'Authorization' : 'AccessKey ' + self.access_key,
35-
'User-Agent' : 'MessageBird/ApiClient/%s Python/%s' % (CLIENT_VERSION, PYTHON_VERSION)
36+
'User-Agent' : 'MessageBird/ApiClient/%s Python/%s' % (CLIENT_VERSION, PYTHON_VERSION),
37+
'Content-Type' : 'application/json'
3638
}
3739

3840
if len(params) == 0:
3941
response = requests.get(url, verify=True, headers=headers)
4042
else:
41-
response = requests.post(url, verify=True, headers=headers, data=params)
43+
response = requests.post(url, verify=True, headers=headers, data=json.dumps(params))
4244

4345
if response.status_code in self._supported_status_codes:
4446
json_response = response.json()

0 commit comments

Comments
 (0)