Python Post - keep getting response 400, but curl works -


i have simple python 3 script send post request delete project in sonarqube. while keep getting in python script, simple curl commands works... idea wrong python script?

import requests  headers = {     'authorization': 'basic ywrtaw46ywrtaw4=', }  files = [     ('key', 'com.eclipseoptions.viewserver:viewserver:feature_vs-313-add-an-instruction-event-and-view'), ]  r = requests.post('http://devsonar/api/projects/delete', headers=headers, files=files) print(r) 

the following curl command works fine:

curl -x post -h "authorization: basic ywrtaw46ywrtaw4=" -f "key=com.eclipseoptions.viewserver:viewserver:feature_vs-313-add-an-instruction-event-and-view" "http://devsonar/api/projects/delete" 

python requests library. files option in post used upload file , don't think com.eclipseoptions.viewserver:viewserver:feature_vs-313-add-an-instruction-event-and-view file if so, have read file in binary mode , send files = {'key': open(filename, 'rb')}. code should be:

import requests files = {'key': open(filename, 'rb')} headers = {'authorization': 'basic ywrtaw46ywrtaw4='} response=requests.post(url,files=files) 

check this details on uploading files using requests library in python.

if not file can send payload directly dictionary this:

import requests headers = {'authorization': 'basic ywrtaw46ywrtaw4='} data = {'key': 'com.eclipseoptions.viewserver:viewserver:feature_vs-313-add-an-instruction-event-and-view'} response=requests.post(url,data=data,headers=headers) 

check this details on sending payload.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -