2016-03-01 39 views
0

我嘗試使用DELETE方法發送{"id": 190}postman tool
它的成功。但我不知道如何與蟒蛇請求Python請求使用數據的DELETE方法

enter image description here

請指引我做到這一點。

下面是代碼:

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

我嘗試:

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

但不下班的500錯誤。

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

+0

刪除'JSON = None'和調用方法時,使用'刪除(網址:{ 「ID」 :190})'。最後通過'kwargs ['id']獲得id# –

回答

1
import json 

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

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

如果您使用請求版本2.4.2或更高

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

謝謝!我遇到了問題。我的代碼是'''return requests.delete(url,json = None,** kwargs)''''''''''''''' – user2492364