Home > Net >  Python: How to login with web browser login prompt in code
Python: How to login with web browser login prompt in code

Time:11-07

I am trying to login into a website from a python script. I read a few tutorials about it and currently I'm stuck at the process to get the login form from the website (how to name the data for username and password). The login button on the website just redirects to another site. On this site a web browser prompt pops up like this

enter image description here

... and ask me to enter the credentials. I was using the inspect tool in chrome to check the traffic during login but there wasn't any POST requests. Only one GET request after login.

Is there a way to get to know the login form for a POST request? Or is a POST request the right way to login on this website at all?

Thanks for you tips and help in advance. Martin

CodePudding user response:

Looks like Basic Auth to me (See Mozilla Developer Network for reference). Assuming your using requests library in python you could give HTTPBasicAuth from requests.auth a try. From https://requests.readthedocs.io/en/latest/user/authentication/ :

from requests.auth import HTTPBasicAuth
basic = HTTPBasicAuth('user', 'pass')
requests.get('https://httpbin.org/basic-auth/user/pass', auth=basic)
  • Related