1

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.

asked Jan 22, 2020 at 14:29
4
  • 1
    You need to check with the API owner or their documentation, it doesn't seem to be related to the requests library. Commented Jan 22, 2020 at 14:33
  • There are a multiple things that server may expect - "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. Commented Jan 22, 2020 at 14:50
  • @gabhijit The response code is 406 Commented Jan 22, 2020 at 15:03
  • if you still can't get it to work, you can workaround using selenium / headless browser, although it's more effort than requests. Commented Jan 19, 2022 at 11:18

2 Answers 2

1

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.

answered Jan 22, 2020 at 14:43
Sign up to request clarification or add additional context in comments.

2 Comments

No, I still get "Not Acceptable!"
webhostingmedia.net/http-error-406-not-acceptable This is likely cause. The way to debug this problem is - Try to submit form through a browser and then try to get same set of headers as are sent by browser.
0

If you have the full url to login you could use this online tool that converts URL to python request:

https://curl.trillworks.com/

If you don't understand the website post full url please.

answered Jan 22, 2020 at 15:12

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.