My school has a website that students can sign up for classes during a study period and I forget all the time. I'm trying to make a script that logs in and signs up for me. This is what I have:
import requests
payload = {
"username": "",
"pwd": "",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246"
}
with requests.Session() as s:
p = s.post('http://www.bloomingtonsouth.org/plus/login.php', data=payload)
print(p.text)
r = s.get('http://www.bloomingtonsouth.org/plus/student.php')
print(r.text)
The output: "Not Acceptable!
Not Acceptable!
An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.
Not Acceptable!Not Acceptable!
An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.
"What am I doing wrong?
Edit 1:
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-US,en;q=0.9",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Host": "bloomingtonsouth.org",
"Referer": "http://bloomingtonsouth.org/plus/login.php",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36"
}
url = "http://www.bloomingtonsouth.org/plus/login.php"
payload = {"username": "", "password": "", "submitted":"TRUE"}
post = requests.post(url, headers=headers, data=payload)
r = requests.get('http://www.bloomingtonsouth.org/plus/student.php')
print(r.text)
I tried this, using the headers I found the browser using and it still doesn't work.
2 Answers 2
User-agent needs to be a header, not in the payload.
login()
def login():
headers = headers - {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246"}
url = "http://www.bloomingtonsouth.org/plus/login.php"
payload = {"username": "", "pwd": ""}
post = requests.post(url, headers=headers, data=payload)
try this code for logging in and let me know if it doesn't work.
2 Comments
If you have the full url to login you could use this online tool that converts URL to python request:
If you don't understand the website post full url please.
requestslibrary."Content-Type"header is properly set? Also, can you also post response code?r.status_code. That might give some indication. If it's 403 - likely your credentials are not right, if it's something else it can then be debugged.