steampy icon indicating copy to clipboard operation
steampy copied to clipboard

set_login_cookies no longer works (Invalid steam_id)

Open HappyWaffle566 opened this issue 1 year ago • 14 comments

Hello. About a week ago the library stopped working. I see that the library is broken due to steam update and tried the solution from pull requests by wolfovik. It did work, but set_login_cookies does not work. It throws me this error:

 File "", line 33, in <module>
    steam_client.set_login_cookies(cookies)
  File "/usr/local/lib/python3.11/dist-packages/steampy/client.py", line 78, in set_login_cookies
    self.steam_guard = {'steamid': str(self.get_steam_id())}
                                       ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/steampy/utils.py", line 23, in func_wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/steampy/client.py", line 89, in get_steam_id
    raise ValueError(f'Invalid steam_id: {steam_id}')
ValueError: Invalid steam_id: None

HappyWaffle566 avatar Jan 22 '24 20:01 HappyWaffle566

for me it happens when session expire each day. have you tried to add new cookies after this error?

Heroslfb avatar Jan 23 '24 09:01 Heroslfb

for me it happens when session expire each day. have you tried to add new cookies after this error?

Well, I wrote the program so if the cookies are expired, they are renewed. First I try to login with cookies (I get them from file) and if they are outdated, then I login without cookies. Then, after each login, I write cookies again in file (I get them using steam_client._session.cookies.get_dict()).

HappyWaffle566 avatar Jan 23 '24 12:01 HappyWaffle566

for me it happens when session expire each day. have you tried to add new cookies after this error?

Well, I wrote the program so if the cookies are expired, they are renewed. First I try to login with cookies (I get them from file) and if they are outdated, then I login without cookies. Then, after each login, I write cookies again in file (I get them using steam_client._session.cookies.get_dict()).

You are not the only one with this problem, after updating the login.py file nothing helps either. Authorization passes, cookies are created, but it is impossible to log in using cookies with the error "Invalid steam_id"

Aarab228 avatar Jan 24 '24 18:01 Aarab228

I don’t remember exactly what I changed in the library, so I attached the files that I changed -> https://drive.google.com/drive/folders/16fm039KSVq1lWut86SWqG7b7Um0zZAPd?usp=sharing

client.py

def set_login_cookies(self, cookies: dict) -> None:
    self._session.cookies.update(cookies)
    self.was_login_executed = True
    if self.steam_guard is None:
        self.steam_guard = {'steamid': str(self.get_steam_id())}
    self.market._set_login_executed(self.steam_guard, self._get_session_id())

login.py

def set_sessionid_cookies(self):
    community_domain = SteamUrl.COMMUNITY_URL[8:]
    store_domain = SteamUrl.STORE_URL[8:]
    community_cookie_dic = self.session.cookies.get_dict(domain=community_domain)
    store_cookie_dic = self.session.cookies.get_dict(domain=store_domain)
    for name in ('steamLoginSecure', 'sessionid', 'steamRefresh_steam', 'steamCountry'):
        cookie = self.session.cookies.get_dict()[name]
        if name in ["steamLoginSecure"]:
            store_cookie = create_cookie(name, store_cookie_dic[name], store_domain)
        else:
            store_cookie = create_cookie(name, cookie, store_domain)

        if name in ["sessionid", "steamLoginSecure"]:
            community_cookie = create_cookie(name, community_cookie_dic[name], community_domain)
        else:
            community_cookie = create_cookie(name, cookie, community_domain)

        self.session.cookies.set(**community_cookie)
        self.session.cookies.set(**store_cookie)

I made all the corrections on January 21st and everything has been working for me since then

Kali1nee avatar Jan 25 '24 02:01 Kali1nee

I don’t remember exactly what I changed in the library, so I attached the files that I changed -> https://drive.google.com/drive/folders/16fm039KSVq1lWut86SWqG7b7Um0zZAPd?usp=sharing

client.py

def set_login_cookies(self, cookies: dict) -> None:
    self._session.cookies.update(cookies)
    self.was_login_executed = True
    if self.steam_guard is None:
        self.steam_guard = {'steamid': str(self.get_steam_id())}
    self.market._set_login_executed(self.steam_guard, self._get_session_id())

login.py

def set_sessionid_cookies(self):
    community_domain = SteamUrl.COMMUNITY_URL[8:]
    store_domain = SteamUrl.STORE_URL[8:]
    community_cookie_dic = self.session.cookies.get_dict(domain=community_domain)
    store_cookie_dic = self.session.cookies.get_dict(domain=store_domain)
    for name in ('steamLoginSecure', 'sessionid', 'steamRefresh_steam', 'steamCountry'):
        cookie = self.session.cookies.get_dict()[name]
        if name in ["steamLoginSecure"]:
            store_cookie = create_cookie(name, store_cookie_dic[name], store_domain)
        else:
            store_cookie = create_cookie(name, cookie, store_domain)

        if name in ["sessionid", "steamLoginSecure"]:
            community_cookie = create_cookie(name, community_cookie_dic[name], community_domain)
        else:
            community_cookie = create_cookie(name, cookie, community_domain)

        self.session.cookies.set(**community_cookie)
        self.session.cookies.set(**store_cookie)

I made all the corrections on January 21st and everything has been working for me since then You have not changed client.py in any way, it is the default. image I changed login.py yesterday to the code you provided, but still no authorization image

image

Aarab228 avatar Jan 25 '24 07:01 Aarab228

I don’t remember exactly what I changed in the library, so I attached the files that I changed -> https://drive.google.com/drive/folders/16fm039KSVq1lWut86SWqG7b7Um0zZAPd?usp=sharing

client.py

def set_login_cookies(self, cookies: dict) -> None:
    self._session.cookies.update(cookies)
    self.was_login_executed = True
    if self.steam_guard is None:
        self.steam_guard = {'steamid': str(self.get_steam_id())}
    self.market._set_login_executed(self.steam_guard, self._get_session_id())

login.py

def set_sessionid_cookies(self):
    community_domain = SteamUrl.COMMUNITY_URL[8:]
    store_domain = SteamUrl.STORE_URL[8:]
    community_cookie_dic = self.session.cookies.get_dict(domain=community_domain)
    store_cookie_dic = self.session.cookies.get_dict(domain=store_domain)
    for name in ('steamLoginSecure', 'sessionid', 'steamRefresh_steam', 'steamCountry'):
        cookie = self.session.cookies.get_dict()[name]
        if name in ["steamLoginSecure"]:
            store_cookie = create_cookie(name, store_cookie_dic[name], store_domain)
        else:
            store_cookie = create_cookie(name, cookie, store_domain)

        if name in ["sessionid", "steamLoginSecure"]:
            community_cookie = create_cookie(name, community_cookie_dic[name], community_domain)
        else:
            community_cookie = create_cookie(name, cookie, community_domain)

        self.session.cookies.set(**community_cookie)
        self.session.cookies.set(**store_cookie)

I made all the corrections on January 21st and everything has been working for me since then

specially copied everything from your files attached on google drive and tried to authorize through cookies, the result is the same image

Aarab228 avatar Jan 25 '24 07:01 Aarab228

@Aarab228 Perhaps you changed library files in the wrong environment? For example, you changed files in pycharm, and included the script using cmd If not, please send an exception so I can understand what's going on.

Kali1nee avatar Jan 25 '24 09:01 Kali1nee

@Aarab228 Perhaps you changed library files in the wrong environment? For example, you changed files in pycharm, and included the script using cmd If not, please send an exception so I can understand what's going on.

I have not changed anything in the library files except for login.py and client.py, the code of which you have given above. The error is "Invalid steam_id: None" when trying to authorize via cookies. Cookies are created at the first login to the account, after which they are used for authorization, but as you understand, authorization fails.

Aarab228 avatar Jan 25 '24 09:01 Aarab228

I don’t remember exactly what I changed in the library, so I attached the files that I changed -> https://drive.google.com/drive/folders/16fm039KSVq1lWut86SWqG7b7Um0zZAPd?usp=sharing

client.py

def set_login_cookies(self, cookies: dict) -> None:
    self._session.cookies.update(cookies)
    self.was_login_executed = True
    if self.steam_guard is None:
        self.steam_guard = {'steamid': str(self.get_steam_id())}
    self.market._set_login_executed(self.steam_guard, self._get_session_id())

login.py

def set_sessionid_cookies(self):
    community_domain = SteamUrl.COMMUNITY_URL[8:]
    store_domain = SteamUrl.STORE_URL[8:]
    community_cookie_dic = self.session.cookies.get_dict(domain=community_domain)
    store_cookie_dic = self.session.cookies.get_dict(domain=store_domain)
    for name in ('steamLoginSecure', 'sessionid', 'steamRefresh_steam', 'steamCountry'):
        cookie = self.session.cookies.get_dict()[name]
        if name in ["steamLoginSecure"]:
            store_cookie = create_cookie(name, store_cookie_dic[name], store_domain)
        else:
            store_cookie = create_cookie(name, cookie, store_domain)

        if name in ["sessionid", "steamLoginSecure"]:
            community_cookie = create_cookie(name, community_cookie_dic[name], community_domain)
        else:
            community_cookie = create_cookie(name, cookie, community_domain)

        self.session.cookies.set(**community_cookie)
        self.session.cookies.set(**store_cookie)

I made all the corrections on January 21st and everything has been working for me since then

Unfortunately, I receive "ValueError: Invalid steam_id: None" as well. Maybe it happens because _session.cookies.get_dict() does not return all cookies?

HappyWaffle566 avatar Jan 25 '24 10:01 HappyWaffle566

@Aarab228 Perhaps you changed library files in the wrong environment? For example, you changed files in pycharm, and included the script using cmd If not, please send an exception so I can understand what's going on.

  1. uninstall steampy image

  2. install steampy image

  3. getting an authorization cookie image

  4. trying to authorize with cookies and perform an action with the market image

Again I get the error invalid steam_id: None. How to fix that, if update by @wolfovik doesn`t work

Aarab228 avatar Jan 25 '24 10:01 Aarab228

I don’t remember exactly what I changed in the library, so I attached the files that I changed -> https://drive.google.com/drive/folders/16fm039KSVq1lWut86SWqG7b7Um0zZAPd?usp=sharing client.py

def set_login_cookies(self, cookies: dict) -> None:
    self._session.cookies.update(cookies)
    self.was_login_executed = True
    if self.steam_guard is None:
        self.steam_guard = {'steamid': str(self.get_steam_id())}
    self.market._set_login_executed(self.steam_guard, self._get_session_id())

login.py

def set_sessionid_cookies(self):
    community_domain = SteamUrl.COMMUNITY_URL[8:]
    store_domain = SteamUrl.STORE_URL[8:]
    community_cookie_dic = self.session.cookies.get_dict(domain=community_domain)
    store_cookie_dic = self.session.cookies.get_dict(domain=store_domain)
    for name in ('steamLoginSecure', 'sessionid', 'steamRefresh_steam', 'steamCountry'):
        cookie = self.session.cookies.get_dict()[name]
        if name in ["steamLoginSecure"]:
            store_cookie = create_cookie(name, store_cookie_dic[name], store_domain)
        else:
            store_cookie = create_cookie(name, cookie, store_domain)

        if name in ["sessionid", "steamLoginSecure"]:
            community_cookie = create_cookie(name, community_cookie_dic[name], community_domain)
        else:
            community_cookie = create_cookie(name, cookie, community_domain)

        self.session.cookies.set(**community_cookie)
        self.session.cookies.set(**store_cookie)

I made all the corrections on January 21st and everything has been working for me since then

Unfortunately, I receive "ValueError: Invalid steam_id: None" as well. Maybe it happens because _session.cookies.get_dict() does not return all cookies?

I was thinking the same thing, however kind of a quick run through the file, I can't find any deviations

Aarab228 avatar Jan 25 '24 10:01 Aarab228

I don’t remember exactly what I changed in the library, so I attached the files that I changed -> https://drive.google.com/drive/folders/16fm039KSVq1lWut86SWqG7b7Um0zZAPd?usp=sharing

client.py

def set_login_cookies(self, cookies: dict) -> None:
    self._session.cookies.update(cookies)
    self.was_login_executed = True
    if self.steam_guard is None:
        self.steam_guard = {'steamid': str(self.get_steam_id())}
    self.market._set_login_executed(self.steam_guard, self._get_session_id())

login.py

def set_sessionid_cookies(self):
    community_domain = SteamUrl.COMMUNITY_URL[8:]
    store_domain = SteamUrl.STORE_URL[8:]
    community_cookie_dic = self.session.cookies.get_dict(domain=community_domain)
    store_cookie_dic = self.session.cookies.get_dict(domain=store_domain)
    for name in ('steamLoginSecure', 'sessionid', 'steamRefresh_steam', 'steamCountry'):
        cookie = self.session.cookies.get_dict()[name]
        if name in ["steamLoginSecure"]:
            store_cookie = create_cookie(name, store_cookie_dic[name], store_domain)
        else:
            store_cookie = create_cookie(name, cookie, store_domain)

        if name in ["sessionid", "steamLoginSecure"]:
            community_cookie = create_cookie(name, community_cookie_dic[name], community_domain)
        else:
            community_cookie = create_cookie(name, cookie, community_domain)

        self.session.cookies.set(**community_cookie)
        self.session.cookies.set(**store_cookie)

I made all the corrections on January 21st and everything has been working for me since then

How to fix send trade offers? Any idea?

kivinblue1 avatar Jan 27 '24 19:01 kivinblue1

I don’t remember exactly what I changed in the library, so I attached the files that I changed -> https://drive.google.com/drive/folders/16fm039KSVq1lWut86SWqG7b7Um0zZAPd?usp=sharing client.py

def set_login_cookies(self, cookies: dict) -> None:
    self._session.cookies.update(cookies)
    self.was_login_executed = True
    if self.steam_guard is None:
        self.steam_guard = {'steamid': str(self.get_steam_id())}
    self.market._set_login_executed(self.steam_guard, self._get_session_id())

login.py

def set_sessionid_cookies(self):
    community_domain = SteamUrl.COMMUNITY_URL[8:]
    store_domain = SteamUrl.STORE_URL[8:]
    community_cookie_dic = self.session.cookies.get_dict(domain=community_domain)
    store_cookie_dic = self.session.cookies.get_dict(domain=store_domain)
    for name in ('steamLoginSecure', 'sessionid', 'steamRefresh_steam', 'steamCountry'):
        cookie = self.session.cookies.get_dict()[name]
        if name in ["steamLoginSecure"]:
            store_cookie = create_cookie(name, store_cookie_dic[name], store_domain)
        else:
            store_cookie = create_cookie(name, cookie, store_domain)

        if name in ["sessionid", "steamLoginSecure"]:
            community_cookie = create_cookie(name, community_cookie_dic[name], community_domain)
        else:
            community_cookie = create_cookie(name, cookie, community_domain)

        self.session.cookies.set(**community_cookie)
        self.session.cookies.set(**store_cookie)

I made all the corrections on January 21st and everything has been working for me since then

How to fix send trade offers? Any idea?

I think you need to replace session_id = self._get_session_id() with self._session.cookies.get_dict()['sessionid'] Atleast that is how I fixed buy_item method for me

HappyWaffle566 avatar Jan 28 '24 08:01 HappyWaffle566

I don’t remember exactly what I changed in the library, so I attached the files that I changed -> https://drive.google.com/drive/folders/16fm039KSVq1lWut86SWqG7b7Um0zZAPd?usp=sharing

client.py

def set_login_cookies(self, cookies: dict) -> None:
    self._session.cookies.update(cookies)
    self.was_login_executed = True
    if self.steam_guard is None:
        self.steam_guard = {'steamid': str(self.get_steam_id())}
    self.market._set_login_executed(self.steam_guard, self._get_session_id())

login.py

def set_sessionid_cookies(self):
    community_domain = SteamUrl.COMMUNITY_URL[8:]
    store_domain = SteamUrl.STORE_URL[8:]
    community_cookie_dic = self.session.cookies.get_dict(domain=community_domain)
    store_cookie_dic = self.session.cookies.get_dict(domain=store_domain)
    for name in ('steamLoginSecure', 'sessionid', 'steamRefresh_steam', 'steamCountry'):
        cookie = self.session.cookies.get_dict()[name]
        if name in ["steamLoginSecure"]:
            store_cookie = create_cookie(name, store_cookie_dic[name], store_domain)
        else:
            store_cookie = create_cookie(name, cookie, store_domain)

        if name in ["sessionid", "steamLoginSecure"]:
            community_cookie = create_cookie(name, community_cookie_dic[name], community_domain)
        else:
            community_cookie = create_cookie(name, cookie, community_domain)

        self.session.cookies.set(**community_cookie)
        self.session.cookies.set(**store_cookie)

I made all the corrections on January 21st and everything has been working for me since then

Could you please make a proper pull request with all changes if everything works fine for you?

yesworId avatar Jan 28 '24 12:01 yesworId