0

I have a school page im trying to login to using requests, and I keep getting this:

{"status":"unauthenticated","errors":[{"message":"user authorization required"}]}

Here is my code,

import requests
from bs4 import BeautifulSoup

POST_LOGIN_URL = 'https://fisd.instructure.com/login/ldap'
REQUEST_URL = 'https://fisd.instructure.com/courses/111538/pages/unit-3-i-week-3'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0',
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'X-Requested-With': 'XMLHttpRequest'
}
payload = {
    'pseudonym_session[unique_id]': (My Username),
    'pseudonym_session[password]': (My Password)
}


with requests.Session() as session:
    post = session.post(POST_LOGIN_URL, data=payload, headers=headers)
    page = session.get(REQUEST_URL, headers=headers)
    print(page.text)

I also want to use

soup = BeautifulSoup(page, "lxml")

print(soup.prettify())

instead of print(page.text) but whenever I run it in VS code I get this error,

Traceback (most recent call last):
  File "/Users/USERNAME/PythonProjects/agenda/Ver2.py", line 22, in <module>
    soup = BeautifulSoup(page, "lxml")
  File "/Users/USERNAME/PythonProjects/agenda/venv/lib/python3.10/site-packages/bs4/__init__.py", line 245, in __init__
    raise FeatureNotFound(
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

but in pycharm im getting a error saying I need javascript to run the webpage. I am very confused why this is happening, as they both have the same file, in the same folder, with the same virtual environment. Any help would be great.

EDIT: I was wondering if this was possible without selenium.

Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
Achilles
  • 46
  • 7
  • Does this answer your question? [How to "log in" to a website using Python's Requests module?](https://stackoverflow.com/questions/11892729/how-to-log-in-to-a-website-using-pythons-requests-module) – baduker Jan 23 '22 at 07:56
  • I actually did it based on that, but the responses don't seem to help – Achilles Jan 23 '22 at 16:34

0 Answers0