send post request python

11,434

Solution 1

Check out the requests library, which you can get via pip by typing pip install requests, either through the cmd prompt, or terminal, depending on your OS.

import requests

payload = {'user' : 'username',
          'pass' : 'PaSSwoRd'}

r = requests.get(r'http://www.URL.com/home', data=payload)

print r.text

You should be alright. If you told us the site in question we could probably provide a better answer.

Solution 2

Yes, it's possible to send the same info as the browser does. Depending on how the browser communicates with the server, it could be as simple as adding username and password as HTTP POST parameters. Other common methods are for the browser to send a hash of the password, or to log in with more than one step.

Solution 3

It's possible to send POST requests from Python. Take a look at httplib, it's standard library for http requests. There are other libraries that could help you act more like a browser. My favorite is mechanize.

Share:
11,434
Jah
Author by

Jah

Updated on June 05, 2022

Comments

  • Jah
    Jah almost 2 years

    I've got a website that I want to check to see if it was updated since the last check (using hash). The problem is that I need to enter a username and password before I can visit the site.

    Is there a way to input the username and the password using python?

  • garnertb
    garnertb almost 12 years
    A solution using the standard python library is preferable.
  • jrennie
    jrennie almost 12 years
    Note that if the server uses HTTP Basic Authentication, you'd use auth= instead of data= in the example.
  • Jah
    Jah almost 12 years
    I'm sorry but I didn't put the site in the question because it's a federal site
  • Cas
    Cas over 9 years
    Is the password sent securely through this method?