Skip to content

Commit

Permalink
keep fake User-Agent header for all requests
Browse files Browse the repository at this point in the history
Looks like some PRONOTE instances actively block clients that have
a weird User-Agent header. It should be fine to send it on all requests.

The header can be changed using:

    import pronotepy.pronoteAPI
    pronotepy.pronoteAPI.HEADERS = { "User-agent": "...", ... }
  • Loading branch information
bain3 committed Aug 19, 2024
1 parent e7bf76e commit c3e7a02
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pronotepy/pronoteAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@
25: "[ERROR 25] Exceeded max authorization requests. Please wait before retrying...",
}

HEADERS = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0",
}


class _Communication(object):
def __init__(
self, site: str, cookies: Optional["RequestsCookieJar"], client: ClientBase
) -> None:
"""Handles all communication with the PRONOTE servers"""
self.root_site, self.html_page = self.get_root_address(site)

self.session = requests.Session()
self.session.headers.update(HEADERS)

self.encryption = _Encryption()
self.attributes: dict = {}
self.request_number = 1
Expand All @@ -57,11 +64,6 @@ def initialise(self) -> Tuple[Any, Any]:
Initialisation of the communication. Sets up the encryption and sends the IV for AES to PRONOTE.
From this point, everything is encrypted with the communicated IV.
"""
# some headers to be real
headers = {
"connection": "keep-alive",
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0",
}

# get rsa keys and session id, retry 3 times
for _ in range(3):
Expand All @@ -70,7 +72,6 @@ def initialise(self) -> Tuple[Any, Any]:
get_response = self.session.request(
"GET",
f"{self.root_site}/{self.html_page}",
headers=headers,
cookies=self.cookies,
)
self.attributes = self._parse_html(get_response.content)
Expand Down

0 comments on commit c3e7a02

Please sign in to comment.