0

I have a python dict in the following format

{'status': ['Done'], 'urgency': 1, 'text': {'shorttext': 'Short Text', 'longtext': 'Long Text'}, 'startdate': '2019-03-03', 'enddate': '2019-03-03'}

which when I convert to json using json_dumps

obj=json_dumps(dict)
print(obj)

'{"status": ["Done"], "urgency": 1, "text": {"shorttext": "Short Text", "longtext": "Long Text"}, "startdate": "2019-03-03", "enddate": "2019-03-03"}'

Now when I try to post this payload to an api using request.post call in the format below

requests.post(url, headers, json=obj)

I get the below error

no String-argument constructor/factory method to deserialize from String value (\'{"status": ["Done"], "urgency": 1, "text": {"shorttext": "Short Text", "longtext": "Long Text"}, "startdate": "2019-03-03", "enddate": "2019-03-03"}'\)

Any inputs on what might be causing this? I suspect is the '' the payload is enclosed in, but am not completely sure. Thanks!

1
  • 1
    You are posting the string instead of the dictionary Commented Sep 11, 2019 at 7:52

1 Answer 1

6

Don't dump the the dict!

requests.post(url, headers, json=dict)

Or, if you have to:

requests.post(url, headers, data=obj)
Sign up to request clarification or add additional context in comments.

1 Comment

you beat me to it. Well done, I have removed my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.