Skip to content

Login redirect raises HTTPStatusError #35

@Vidminas

Description

@Vidminas

A simple login snippet is problematic:

from getpass import getpass

USERNAME = getpass('Enter your user name:')
PASSWORD = getpass('Enter your password:')
IDP = 'https://solidcommunity.net'

from solid.solid_api import SolidAPI, Auth

auth = Auth()
api = SolidAPI(auth)
auth.login(IDP, USERNAME, PASSWORD)

running this raises HTTPStatusError: Redirect response '302 Found' for url 'https://solidcommunity.net/login/password'.

Full stack trace HTTPStatusError Traceback (most recent call last) Cell In[1], line 11 9 auth = Auth() 10 api = SolidAPI(auth) ---> 11 auth.login(IDP, USERNAME, PASSWORD)

File c:\Users\Vidminas.conda\envs\solid\Lib\site-packages\solid\auth.py:25, in Auth.login(self, idp, username, password)
23 r = self.client.post(url, data=data)
24 # print(r)
---> 25 r.raise_for_status()
27 if not self.is_login:
28 raise Exception('Cannot login.')

File c:\Users\Vidminas.conda\envs\solid\Lib\site-packages\httpx_models.py:736, in Response.raise_for_status(self)
734 error_type = error_types.get(status_class, "Invalid status code")
735 message = message.format(self, error_type=error_type)
--> 736 raise HTTPStatusError(message, request=request, response=self)

HTTPStatusError: Redirect response '302 Found' for url 'https://solidcommunity.net/login/password'
Redirect location: 'https://solidrive.solidcommunity.net/'
For more information check: https://httpstatuses.com/302

Looking at the source, the cause is in auth.py:

r = self.client.post(url, data=data)
r.raise_for_status()

I think this broke in #29, when dependabot bumped the version of httpx.
In the previous version (httpx 0.18.2), raise_for_status used to only raise an exception if the status code was a 4xx code (https://github.com/encode/httpx/blob/0.18.2/httpx/_models.py#L1384). In the newer version (httpx 0.23.0), raise_for_status raises an exception if the status is not a 2xx code, which includes redirects (https://github.com/encode/httpx/blob/0.23.0/httpx/_models.py#L701)

The code in auth.py should probably be wrapped in:

if not r.is_redirect:
    r.raise_for_status()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions