0

I am trying to use Python 3 to log in on this page:

https://sentral.hillsgrammar.nsw.edu.au/portal/login

And then I want to navigate to another page to download a file.

My problem is that I have tried the urllib basic authentication---that doesn't seem to work I tried doing something like this:

auth_handler = urllib.request.HTTPBasicAuthHandler()
auth_handler.add_password(realm='sentral.hillsgrammar.nsw.edu.au',
                          uri='http://sentral.hillsgrammar.nsw.edu.au/portal/login',
                          user='USERNAME',
                          passwd='PASSWORD')
opener = urllib.request.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib.request.install_opener(opener)
print(urllib.request.urlopen('http://sentral.hillsgrammar.nsw.edu.au/portal/dashboard').read())

Although I don't know if this is the actual realm---just a guess. so why does this code come up with the login pages as HTML rather then the dashboard? Why does it not authenticate?

Thanks, Itechmatrix

EDIT: My new code:

from requests import session

payload = {
    'action': 'login',
    'username': username,
    'password': password
}

with session() as c:
    c.post('http://sentral.hillsgrammar.nsw.edu.au/portal/login', data=payload)
    request = c.get('http://sentral.hillsgrammar.nsw.edu.au/portal/timetable/mytimetable')
    print(request.headers)
    print(request.text)
user24492
  • 37
  • 6

0 Answers0