dbosk / ladok3

Python wrapper around the LADOK3 REST API.
https://pypi.org/project/ladok3/
MIT License
5 stars 1 forks source link

Caching doesn't work with AutologinSession #65

Closed dbosk closed 1 year ago

dbosk commented 1 year ago

There seems to be a problem with the cache and AutologinSession. After a completed run we get:

Traceback (most recent call last):
  File "/home/dbosk/.local/bin/ladok", line 8, in <module>
    sys.exit(main())
  File "/home/dbosk/.local/lib/python3.10/site-packages/ladok3/cli.py", line 340, in main
    args.func(ls, args)
  File "/home/dbosk/.local/lib/python3.10/site-packages/ladok3/data.py", line 158, in command
    for student, component, grade, time in data:
  File "/home/dbosk/.local/lib/python3.10/site-packages/ladok3/data.py", line 19, in extract_data_for_round
    results = ladok.search_reported_results_JSON(
  File "/home/dbosk/.local/lib/python3.10/site-packages/ladok3/__init__.py", line 332, in search_reported_results_JSON
    response = self.put_query(
  File "/home/dbosk/.local/lib/python3.10/site-packages/ladok3/__init__.py", line 114, in put_query
    return self.session.put(
  File "/home/dbosk/.local/lib/python3.10/site-packages/requests/sessions.py", line 647, in put
    return self.request("PUT", url, data=data, **kwargs)
  File "/home/dbosk/.local/lib/python3.10/site-packages/weblogin/__init__.py", line 50, in request
    for handler in self.__handlers:
AttributeError: 'AutologinSession' object has no attribute '_AutologinSession__handlers'
dbosk commented 1 year ago

Turns out that requests.Session has a method __getstate__ that overrides the default. Since we don't define a new one in AutologinSession, that one is used --- and that one doesn't include the .__handlers attribute from AutologinSession.