j-andrews7 / kenpompy

A simple yet comprehensive web scraper for kenpom.com.
https://kenpompy.readthedocs.io/en/latest/?badge=latest
GNU General Public License v3.0
71 stars 21 forks source link

Enhancement: Add login failure detection #23

Closed esqew closed 1 year ago

esqew commented 2 years ago

Logging into KenPom with MechanicalSoup is a bit wonky in that the service seems to always return 200 OK status code even on a credential-related failure. This leads to confusion like in #15 where one might assume a login was successful as no exception was thrown, but downstream encounters issues trying to pull data requiring a valid session.

On further inspection, it seems the difference the response for a successful login and an unsuccessful one (due to incorrect credentials) is that the Set-Cookie response header returns a PHPSESSID for successful logins, and cookie invalidation information otherwise. As such, I've updated utils.py to look for the string "PHPSESSID=" in the response header value for Set-Cookie and, in its absence, throw the Logging in to kenpom.com failed Exception. I've also added logic into tests/conftest.py to ensure that pytest aborts when the login fails (as most tests will begin failing without a successful login anyway).

If you can, I could use some help testing this in verifying that everyone does indeed get a Set-Cookie: "PHPSESSID=..." header on successful login before this gets merged in.

j-andrews7 commented 2 years ago

Missed this, thanks for the PR. I'll take try to test soon.