ChatExchange icon indicating copy to clipboard operation
ChatExchange copied to clipboard

ValueError on method `client.get_me` without logging in.

Open wchistow opened this issue 1 year ago • 1 comments

When I tried to call get_me() method of the Client class without passing email and password to its constructor, I got this error:

>>> import chatexchange
>>> client = chatexchange.Client()
>>> client.get_me()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/.../chatexchange/client.py", line 158, in get_me
    assert self._br.user_id is not None
           ^^^^^^^^^^^^^^^^
  File "/.../chatexchange/_utils.py", line 104, in __get__
    method()
  File "/.../chatexchange/browser.py", line 251, in _update_chat_fkey_and_user
    self._load_user(favorite_soup)
  File "/.../chatexchange/browser.py", line 233, in _load_user
    user_id, user_name = self.user_id_and_name_from_link(user_link_soup)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../chatexchange/browser.py", line 242, in user_id_and_name_from_link
    user_id = int(split_link[split_link.index('users') + 1])
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'login?returnurl=https%3a%2f%2fchat.stackexchange.com%2fchats%2fjoin%2ffavorite'

I think, this should be not ValueError, but for example your own error something like NotLoggedInError.

wchistow avatar May 21 '24 11:05 wchistow

While I agree that would be better in an ideal world, making that change now would be a breaking change for all existing users of this package. We definitely already look for a ValueError there, and only a ValueError, to indicate that login wasn't successful.

makyen avatar May 21 '24 12:05 makyen