Python - login to website using requests
Question: I have to admit I am complitely clueless about this: I need to login to this
site <https://segreteriaonline.unisi.it/Home.do> and then perform some
actions. Problem is I cannot find the form to use in the source of the
webpage, and I basically have never tried to login to a website via python.
This is the simple code I wrote.

    
    
    import requests
    
    url_from    = 'https://segreteriaonline.unisi.it/Home.do'
    url_in      = 'https://segreteriaonline.unisi.it/auth/Logon.do'
    
    data = {'form':'1', 'username':'myUser', 'password':'myPass'}
    
    s = requests.session()
    s.get(url_from)
    r = s.post(url_in, data)
    
    print r
    

Obviously, what i get is:

    
    
    <Response [401]>
    

Any suggestions? Thanks in advance.


Answer: You need to use the requests authentication header.

Please check [here](http://docs.python-
requests.org/en/latest/user/authentication/):

    
    
    from requests.auth import HTTPBasicAuth
    requests.get('https://api.github.com/user', auth=HTTPBasicAuth('user', 'pass'))
    <Response [200]>
    

