bukson / steampy

A Steam trading library for python 3
MIT License
561 stars 153 forks source link

False Session // Steam update? #365

Open Requestedd opened 7 months ago

Requestedd commented 7 months ago

Good afternoon!

I used the following code to log in to the steam:


def сreate_steam_session():
    print("You not authorized, trying to login into Steam\nSigning in steam account")

    steamid, shared_secret_key, identity_secret_key, api_key, username, password = data.data_path.login_data_steam()

    steamguard_data = {
        "steamid": steamid,
        "shared_secret": shared_secret_key,
        "identity_secret": identity_secret_key
    }

    steamguard_data = json.dumps(steamguard_data)

    steam_client = SteamClient(api_key)

    steam_client._session.cookies.set("steamRememberLogin", 'true')

    steam_client.login(username, password, steamguard_data)

    print('Saving session')
    with open(f'{pkl_name}', 'wb') as f:
        pickle.dump(steam_client, f)
    return steam_client

def authorization():
    if os.path.isfile(f"{pkl_name}"):
        print('Using previous session')
        with open(f'{pkl_name}', 'rb') as f:
            steam_client = pickle.load(f)

        session_alive = steam_client.is_session_alive()
        if not session_alive:
            support_package.color_out_text.color_text('R', f'Session dead {session_alive}')
            os.remove(f"{pkl_name}")
            support_package.color_out_text.color_text('G', f'Create new session {session_alive}')
            steam_client = сreate_steam_session()
    else:
        steam_client = сreate_steam_session()
    return steam_client

I also realized that steam had updated something , and changed the value in steampy/login.py :


# def set_sessionid_cookies(self):
    #     community_domain = SteamUrl.COMMUNITY_URL[8:]
    #     store_domain = SteamUrl.STORE_URL[8:]
    #     for name in ('steamLoginSecure', 'sessionid', 'steamRefresh_steam', 'steamCountry'):
    #         cookie = self.session.cookies.get_dict()[name]
    #         community_cookie = create_cookie(name, cookie, community_domain)
    #         store_cookie = create_cookie(name, cookie, store_domain)
    #         self.session.cookies.set(**community_cookie)
    #         self.session.cookies.set(**store_cookie)

    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)

It helped me and worked for a while. But yesterday the session stopped being saved again.

Can you share your opinion? Is the authorization working and is the session saved? If so, what code are you using?

Requestedd commented 7 months ago

Correction: Now this code seems to be working, the session is fine again. But it is unclear why the code was not operational for 2 days.

SiSiska commented 7 months ago

File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\steampy\client.py", line 318, in make_offer if response.get('needs_mobile_confirmation'): ^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'get'

my knowledge is not enough to understand why status_code: 401

kostrv commented 7 months ago

I am also facing this problem but there is a point where I am not able to get the market data. I've tried using cookie authentication and steamguard data authentication but there is no difference, I always get bad results and get an empty dictionary. In the case of using a session cookie, the is_session_alive() function returned true, but when I did the same thing, but using Steamguard, I got a false result.

SiSiska commented 7 months ago

I checked the steamguard codes, everything is fine with them, they are exactly the same as in other programs and everything works in them. I compared the post sent in the browser and the post in request module. There are no external changes, but something is wrong and the post sessionid is not accepted.

SiSiska commented 7 months ago

client.py

    def _get_session_id(self) -> str:
        return self._session.cookies.get_dict("steamcommunity.com")['sessionid']
kostrv commented 7 months ago
    def _get_session_id(self) -> str:
        return self._session.cookies.get_dict()("steamcommunity.com")['sessionid']

I tried this but encountered incompatibility. I dont think what it is actualy an issue place, at least in my case, my get_dict() method returns the correct values

image

image

image

SiSiska commented 7 months ago

I misspelled the parentheses. fix it client.py

    def _get_session_id(self) -> str:
        return self._session.cookies.get_dict("steamcommunity.com")['sessionid']