Making a successful Python HTTP POST Request -


i trying write python script make request desktop application listening 8080 port. below code use make request.

import requests   payload = {"url":"abcdefghiklmnopqrstuvwxyz=", "password":"qertyuioplkjhgfdsazxvnm=", "token":"abcdefghijklmn1254786=="}  headers = {'content-type':'application/json'} r = requests.post('http://localhost:9015/login',params = payload, headers=headers) response = requests.get("http://localhost:9015/login") print(r.status_code) 

after making request, response code of 401.

however, when try same using postman app, successful response. following details give in postman:

url: http://localhost:9015/login method : post headers: content-type:application/json body: {"url":"abcdefghiklmnopqrstuvwxyz=",        "password":"qertyuioplkjhgfdsazxvnm=",        "token":"abcdefghijklmn1254786=="} 

can suggestions on going wrong python script?

you pass params, when should pass data, or, better, json setting content-type automatically. so, should be:

import json r = requests.post('http://localhost:9015/login', data=json.dumps(payload), headers=headers) 

or

r = requests.post('http://localhost:9015/login', json=payload) 

(params adds key-value pairs query parameters in url)


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -