1

I try to send {"id": 190} with DELETE method in postman tool
It's success . But I don't know how to do this with python requests

enter image description here

Please guide me .

Here is the code :

def delete(url, json=None,**kwargs):
    return requests.delete(url, json=None,**kwargs)

I try:

delete(url,json={"id":190})

But not work got 500 error .

org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]

1
  • remove json=None and when calling the method use delete(url,{"id":190}). Finally get the id by kwargs['id'] Commented Mar 1, 2016 at 4:58

1 Answer 1

2
import json

data = {"id":190}
data = json.dumps(data)

def delete(url, json=None,**kwargs):
    return requests.delete(url, data=json.dumps(data),**kwargs)

If you are using requests version 2.4.2 or higher

def delete(url, json=None,**kwargs):
        return requests.delete(url, json=data,**kwargs)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I got the problem. mine is return requests.delete(url, json=None,**kwargs) It should return requests.delete(url, json=json,**kwargs)

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.