Python + requests, How I send username & password in POST?

StasM

I am using python + requests to integrate with qTest REST API. I have a problem on the first step of the login process.

I need to create a POST massage that looks like that:

POST /api/login
Host: nephele.qtestnet.com  
Cache-Control: no-cache  
Content-Type: application/x-www-form-urlencoded  
j_username= maxmccloud%40qasymphony.com&j_password=p@ssw0rd 

I did this on python:

r = requests.post("http://indegy.qtestnet.com/api/login",data="j_username= maxmccloud%40qasymphony.com&j_password=p@ssw0rd")
print r.text

But when I run it it says:

{"message": "Login failed. Invalid username or password."}

Martijn Pieters

Just pass the username and password in a dictionary to the data argument; requests will then encode the information for you. Use unencoded data, so use @ instead of %40, for example:

data = {
    'j_username': '[email protected]',
    'j_password': 'p@ssw0rd'
}

response = requests.post(
    'http://indegy.qtestnet.com/api/login',
    data=data
)

requests will then encode the dictionary and set the Content-Type header to application/x-www-form-urlencoded as well.

See the More complicated POST requests section in the Quickstart documentation.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Is it possible to send python requests data in format "&username=login&password=password"

How can I send username and password to an express server with ajax?

XMLHttpRequest: How do I pass 'POST' parameters safely (username, password)?

Username/password proxies not working correctly python requests

How to send username, password and click submit button

How to send username and password using RestClient

How do I add a loop to a username and password login (Python)?

How to send cookies in a post request with the Python Requests library?

How to send cookies in a post request with the Python Requests library?

How to send a post request with data using python requests module?

How to send '-X POST' using 'requests' library in Python?

How to Post data username password for login

Is it secure to send username and password in a Json object in the body of a post request?

How do I send a username and password to git's credential user prompt from my powershell script?

How Can I Enter Username And Password Outputs To A MySQL Server Without Using POST or GET

Python: How can i send multiple HTTP requests and receive the response?

http requests with username and password in ruby

How do I set the SMB username and password?

How can I save username and password in Git?

How do I provide a username and password to wget?

How to send POST requests from dynamic fields?

How to send XML POST requests with Spring RestTemplate?

How to send XML POST requests using JMeter

How to send multiple POST requests in JavaScript

How to send AND receive POST requests with JavaScript HTML

How to send username and password in popup box through selenium in java?

How to send Username/Password and a Cookie using stream_context_create()

How to set username and password and send request to identity provider in simplesamlphp?

How to get Python MYSQL connection username and password?