Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steam cookies not working #343

Closed
denghuols opened this issue Jan 18, 2024 · 38 comments
Closed

Steam cookies not working #343

denghuols opened this issue Jan 18, 2024 · 38 comments

Comments

@denghuols
Copy link

denghuols commented Jan 18, 2024

I logged into steam via my steam username and password, but when I checked my session I found it had expired。
image
When I printed the login-related parameters, I found that everything was normal, but the cookie had expired. This situation suddenly appeared today
Thanks for your answer

@songshijun007
Copy link

me too, cant promise order

@BuyerProject
Copy link

Now steamcommunity.com store.steampowered.com are separate and each steamLoginSecure works separately

@denghuols
Copy link
Author

Now steamcommunity.com store.steampowered.com are separate and each steamLoginSecure works separately
Please tell me what should I do to modify the code to fix this bug?

@wolfovik
Copy link
Contributor

So we will share too. Everything will be ready soon!

@crab713
Copy link

crab713 commented Jan 18, 2024

just cancel set_sessionid_cookies() in LoginExecutor, login(), line 46, can login steamcommunity.com and send trade offer.But I don't know any bad effect with this operation.Waiting for ahthor update.

def login(self) -> Session:
        login_response = self._send_login_request()
        if len(login_response.json()['response']) == 0:
            raise ApiException('No response received from Steam API. Please try again later.')
        self._check_for_captcha(login_response)
        self._update_steam_guard(login_response)
        finallized_response = self._finalize_login()
        self._perform_redirects(finallized_response.json())
        # self.set_sessionid_cookies() # cancel this
        return self.session

@denghuols
Copy link
Author

just cancel set_sessionid_cookies() in LoginExecutor, login(), line 46, can login steamcommunity.com and send trade offer.But I don't know any bad effect with this operation.Waiting for ahthor update.

def login(self) -> Session:
        login_response = self._send_login_request()
        if len(login_response.json()['response']) == 0:
            raise ApiException('No response received from Steam API. Please try again later.')
        self._check_for_captcha(login_response)
        self._update_steam_guard(login_response)
        finallized_response = self._finalize_login()
        self._perform_redirects(finallized_response.json())
        # self.set_sessionid_cookies() # cancel this
        return self.session

This solution is right , I found the steamcommunity.com and steampowered.com can't share the same sessionId which make the bug.

@wolfovik
Copy link
Contributor

I think we shouldn't disable this code. Doing so might disrupt trading operations. It's better to just assign a unique LoginSecure to each domain, similar to what Steam did.

@wolfovik
Copy link
Contributor

wolfovik commented Jan 18, 2024

@ #344

#49de498

@jjh4568520
Copy link

@ #344

#49de498

create_cookie

@BuyerProject
Copy link

BuyerProject commented Jan 18, 2024

Does buying and selling work for you?

@wolfovik
Copy link
Contributor

Does buying and selling work for you?

Yes, everything is working as before.

@jjh4568520
Copy link

Does buying and selling work for you?

Yes, everything is working as before.

del self._
community_cookie = self._create_cookie(name, community_cookie_dic['steamLoginSecure'], community_domain)
store_cookie = self._create_cookie(name, store_cookie_dic['steamLoginSecure'], store_domain)

community_cookie = create_cookie(name, community_cookie_dic['steamLoginSecure'], community_domain)
store_cookie = create_cookie(name, store_cookie_dic['steamLoginSecure'], store_domain)

@spsdamn
Copy link

spsdamn commented Jan 18, 2024

just cancel set_sessionid_cookies() in LoginExecutor, login(), line 46, can login steamcommunity.com and send trade offer.But I don't know any bad effect with this operation.Waiting for ahthor update.

def login(self) -> Session:
        login_response = self._send_login_request()
        if len(login_response.json()['response']) == 0:
            raise ApiException('No response received from Steam API. Please try again later.')
        self._check_for_captcha(login_response)
        self._update_steam_guard(login_response)
        finallized_response = self._finalize_login()
        self._perform_redirects(finallized_response.json())
        # self.set_sessionid_cookies() # cancel this
        return self.session

i used this solution, but i got none response in response = self._session.post(url, data=params, headers=headers)

@crab713
Copy link

crab713 commented Jan 18, 2024

just cancel set_sessionid_cookies() in LoginExecutor, login(), line 46, can login steamcommunity.com and send trade offer.But I don't know any bad effect with this operation.Waiting for ahthor update.

def login(self) -> Session:
        login_response = self._send_login_request()
        if len(login_response.json()['response']) == 0:
            raise ApiException('No response received from Steam API. Please try again later.')
        self._check_for_captcha(login_response)
        self._update_steam_guard(login_response)
        finallized_response = self._finalize_login()
        self._perform_redirects(finallized_response.json())
        # self.set_sessionid_cookies() # cancel this
        return self.session

i used this solution, but i got none response in response = self._session.post(url, data=params, headers=headers)

recommend to use wolfovik solution,#344.
None response maybe due to your network, I can use this solution send and accept offer few hours ago.

@kingofthebongo11
Copy link

kingofthebongo11 commented Jan 18, 2024

iam beginner on gh. Dont know how post correctly post recommend. But now login with cookies dont work correctly. I fixed it with next code.
def cookies_to_list(cookies: requests.cookies.RequestsCookieJar) -> list:
cookies_list = []
for cookie in cookies:
cookie_dict = {
'name': cookie.name,
'value': cookie.value,
'domain': cookie.domain,
'path': cookie.path,
'expires': cookie.expires
}
cookies_list.append(cookie_dict)
return cookies_list

def save_cookies_to_file(cookies_list: list, file_path: str):
with open(file_path, 'w') as file:
json.dump(cookies_list, file)

def load_cookies_from_file(file_path: str):
with open(file_path, 'r') as file:
cookies_list = json.load(file)
cookie_jar = requests.cookies.RequestsCookieJar()
for cookie in cookies_list:
cookie_jar.set(cookie['name'], cookie['value'], domain=cookie.get('domain'), path=cookie.get('path'), expires=cookie.get('expires'))
return cookie_jar
add this 3 functions in utils.py
and save_cookies_to_file(cookies_to_list(self.session.cookies), 'cookies.json') to set_sessionid_cookies(self): in login.py
and in client.py:
login_cookies: str = None, in construction.

def set_login_cookies(self, cookies) -> None:
    self._session.cookies = load_cookies_from_file(cookies)
    self.was_login_executed = True
    if not self.steam_guard.get('steamid'):
        self.steam_guard['steamid'] = str(self.get_steam_id())
    self.market._set_login_executed(self.steam_guard, self._get_session_id())  and rewrite this function

@xidios
Copy link

xidios commented Jan 18, 2024

@ #344

#49de498

I use the library to get cookies for further posts in the discussion. Your solution gives me invalid cookies, since my requests return a 401 status code(
Maybe someone knows how to fix this?

@vmee
Copy link

vmee commented Jan 19, 2024

@ #344

#49de498

buy_item is no work: There are multiple cookies with name, 'sessionid'

@caramilk
Copy link

caramilk commented Jan 19, 2024

@ #344
#49de498

I use the library to get cookies for further posts in the discussion. Your solution gives me invalid cookies, since my requests return a 401 status code( Maybe someone knows how to fix this?

Make sure that you are using the 'sessionid' value of domain 'steamcommunity.com' for the trade offer request parameters, there are multiple cookies with the same name 'sessionid' in the cookiejar, you have to explicitly choose the value of the correct domain.

@iWeeDev
Copy link

iWeeDev commented Jan 19, 2024

@ #344

#49de498

This fix is not working for me using username, pass and shared_secret to login.

Any idea how to fix it? This is the traceback:

Traceback (most recent call last): File "C:\Users\Administrator2\AppData\Local\Programs\Python\Python310\lib\site-packages\steampy\client.py", line 110, in login LoginExecutor(self.username, self._password, self.steam_guard['shared_secret'], self._session).login() File "C:\Users\Administrator2\AppData\Local\Programs\Python\Python310\lib\site-packages\steampy\login.py", line 41, in login self.set_sessionid_cookies() File "C:\Users\Administrator2\AppData\Local\Programs\Python\Python310\lib\site-packages\steampy\login.py", line 59, in set_sessionid_cookies community_cookie = self._create_cookie(name, community_cookie_dic['steamLoginSecure'], community_domain) AttributeError: 'LoginExecutor' object has no attribute '_create_cookie'

@xidios
Copy link

xidios commented Jan 19, 2024

@ #344
#49de498

This fix is not working for me using username, pass and shared_secret to login.

Any idea how to fix it? This is the traceback:

Traceback (most recent call last): File "C:\Users\Administrator2\AppData\Local\Programs\Python\Python310\lib\site-packages\steampy\client.py", line 110, in login LoginExecutor(self.username, self._password, self.steam_guard['shared_secret'], self._session).login() File "C:\Users\Administrator2\AppData\Local\Programs\Python\Python310\lib\site-packages\steampy\login.py", line 41, in login self.set_sessionid_cookies() File "C:\Users\Administrator2\AppData\Local\Programs\Python\Python310\lib\site-packages\steampy\login.py", line 59, in set_sessionid_cookies community_cookie = self._create_cookie(name, community_cookie_dic['steamLoginSecure'], community_domain) AttributeError: 'LoginExecutor' object has no attribute '_create_cookie'

replace self._create_cookie on create_cookie

@xidios
Copy link

xidios commented Jan 19, 2024

@ #344
#49de498

I use the library to get cookies for further posts in the discussion. Your solution gives me invalid cookies, since my requests return a 401 status code( Maybe someone knows how to fix this?

Make sure that you are using the 'sessionid' value of domain 'steamcommunity.com' for the trade offer request parameters, there are multiple cookies with the same name 'sessionid' in the cookiejar, you have to explicitly choose the value of the correct domain.

hmm i tried
session.cookies.get_dict("steamcommunity.com")
but it doesn't work :(

@iWeeDev
Copy link

iWeeDev commented Jan 19, 2024

@ #344
#49de498

This fix is not working for me using username, pass and shared_secret to login.
Any idea how to fix it? This is the traceback:
Traceback (most recent call last): File "C:\Users\Administrator2\AppData\Local\Programs\Python\Python310\lib\site-packages\steampy\client.py", line 110, in login LoginExecutor(self.username, self._password, self.steam_guard['shared_secret'], self._session).login() File "C:\Users\Administrator2\AppData\Local\Programs\Python\Python310\lib\site-packages\steampy\login.py", line 41, in login self.set_sessionid_cookies() File "C:\Users\Administrator2\AppData\Local\Programs\Python\Python310\lib\site-packages\steampy\login.py", line 59, in set_sessionid_cookies community_cookie = self._create_cookie(name, community_cookie_dic['steamLoginSecure'], community_domain) AttributeError: 'LoginExecutor' object has no attribute '_create_cookie'

replace self._create_cookie on create_cookie

I think I did that. This is my current function:

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 == 'steamLoginSecure':
          community_cookie = self._create_cookie(name, community_cookie_dic['steamLoginSecure'], community_domain)
          store_cookie = self._create_cookie(name, store_cookie_dic['steamLoginSecure'], store_domain)
      else:
          community_cookie = self._create_cookie(name, cookie, community_domain)
          store_cookie = self._create_cookie(name, cookie, store_domain)

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

Am I missing something?

@xidios
Copy link

xidios commented Jan 19, 2024

@ #344
#49de498

This fix is not working for me using username, pass and shared_secret to login.
Any idea how to fix it? This is the traceback:
Traceback (most recent call last): File "C:\Users\Administrator2\AppData\Local\Programs\Python\Python310\lib\site-packages\steampy\client.py", line 110, in login LoginExecutor(self.username, self._password, self.steam_guard['shared_secret'], self._session).login() File "C:\Users\Administrator2\AppData\Local\Programs\Python\Python310\lib\site-packages\steampy\login.py", line 41, in login self.set_sessionid_cookies() File "C:\Users\Administrator2\AppData\Local\Programs\Python\Python310\lib\site-packages\steampy\login.py", line 59, in set_sessionid_cookies community_cookie = self._create_cookie(name, community_cookie_dic['steamLoginSecure'], community_domain) AttributeError: 'LoginExecutor' object has no attribute '_create_cookie'

replace self._create_cookie on create_cookie

I think I did that. This is my current function:

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 == 'steamLoginSecure':
          community_cookie = self._create_cookie(name, community_cookie_dic['steamLoginSecure'], community_domain)
          store_cookie = self._create_cookie(name, store_cookie_dic['steamLoginSecure'], store_domain)
      else:
          community_cookie = self._create_cookie(name, cookie, community_domain)
          store_cookie = self._create_cookie(name, cookie, store_domain)

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

Am I missing something?

I replaced self._create_cookie with create_cookie in the code below

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 == 'steamLoginSecure':
          community_cookie = create_cookie(name, community_cookie_dic['steamLoginSecure'], community_domain)
          store_cookie = create_cookie(name, store_cookie_dic['steamLoginSecure'], store_domain)
      else:
          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)

@iWeeDev
Copy link

iWeeDev commented Jan 19, 2024

@ #344
#49de498

This fix is not working for me using username, pass and shared_secret to login.
Any idea how to fix it? This is the traceback:
Traceback (most recent call last): File "C:\Users\Administrator2\AppData\Local\Programs\Python\Python310\lib\site-packages\steampy\client.py", line 110, in login LoginExecutor(self.username, self._password, self.steam_guard['shared_secret'], self._session).login() File "C:\Users\Administrator2\AppData\Local\Programs\Python\Python310\lib\site-packages\steampy\login.py", line 41, in login self.set_sessionid_cookies() File "C:\Users\Administrator2\AppData\Local\Programs\Python\Python310\lib\site-packages\steampy\login.py", line 59, in set_sessionid_cookies community_cookie = self._create_cookie(name, community_cookie_dic['steamLoginSecure'], community_domain) AttributeError: 'LoginExecutor' object has no attribute '_create_cookie'

replace self._create_cookie on create_cookie

I think I did that. This is my current function:

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 == 'steamLoginSecure':
          community_cookie = self._create_cookie(name, community_cookie_dic['steamLoginSecure'], community_domain)
          store_cookie = self._create_cookie(name, store_cookie_dic['steamLoginSecure'], store_domain)
      else:
          community_cookie = self._create_cookie(name, cookie, community_domain)
          store_cookie = self._create_cookie(name, cookie, store_domain)

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

Am I missing something?

I replaced self._create_cookie with create_cookie in the code below

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 == 'steamLoginSecure':
          community_cookie = create_cookie(name, community_cookie_dic['steamLoginSecure'], community_domain)
          store_cookie = create_cookie(name, store_cookie_dic['steamLoginSecure'], store_domain)
      else:
          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)

Sorry, I didn´t get you before.

Great, it´s working now. Thank you so much!

@OlegAlyeynikov
Copy link

OlegAlyeynikov commented Jan 19, 2024

I'm using the buy item method from the steampy library. Before this, this method worked normally. And for the last two days I’ve been receiving this response:

{'message': 'There was a problem purchasing your item. The listing may have been removed. Refresh the page and try again.'}

2024-01-19 18:26:33,196 - my_logger - WARNING - There was a problem buying this item. Message: There was a problem buying this item. Message: There was a problem purchasing your item. The listing may have been removed. Refresh the page and try again.

I tried everything above, nothing worked.
I just can’t cope with this problem, can someone tell me something?

@xidios
Copy link

xidios commented Jan 19, 2024

My fix for steamcommunity.com cookies

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)
        for name in ('steamLoginSecure', 'sessionid', 'steamRefresh_steam', 'steamCountry'):
            cookie = self.session.cookies.get_dict()[name]
            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)
            store_cookie = create_cookie(name, cookie, store_domain)
            self.session.cookies.set(**community_cookie)
            self.session.cookies.set(**store_cookie)

@HappyWaffle566
Copy link

HappyWaffle566 commented Jan 19, 2024

I tried all solutions from this issue and I always get one problem: it works through time and I get this error:
KeyError: 'refresh_token'
Is there something I can do?

@SamuelKollar
Copy link

@HappyWaffle566 I get the same error

@xidios
Copy link

xidios commented Jan 19, 2024

Fixed code for cookies:

in 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)

in client.py (if you use accept trade offer function):

    @login_required
    def accept_trade_offer(self, trade_offer_id: str) -> dict:
        trade = self.get_trade_offer(trade_offer_id)
        trade_offer_state = TradeOfferState(trade['response']['offer']['trade_offer_state'])
        if trade_offer_state is not TradeOfferState.Active:
            raise ApiException(f'Invalid trade offer state: {trade_offer_state.name} ({trade_offer_state.value})')

        partner = self._fetch_trade_partner_id(trade_offer_id)
        session_id = self._session.cookies.get_dict("steamcommunity.com")['sessionid']
        accept_url = f'{SteamUrl.COMMUNITY_URL}/tradeoffer/{trade_offer_id}/accept'
        params = {
            'sessionid': session_id,
            'tradeofferid': trade_offer_id,
            'serverid': '1',
            'partner': partner,
            'captcha': '',
        }
        headers = {'Referer': self._get_trade_offer_url(trade_offer_id)}

        response = self._session.post(accept_url, data=params, headers=headers).json()
        if response.get('needs_mobile_confirmation', False):
            return self._confirm_transaction(trade_offer_id)

        return response

In general, if you need to restore the functionality of functions, then you need to check calls to self._session.cookies.get_dict and pass the required domain

I only tested the code for steamcommunity, so let me know if anything doesn't work

@OlegAlyeynikov
Copy link

Fixing the code for cookies as described above does not work for me.
Using buy_item method i get response:
{'message': 'There was a problem purchasing your item. The listing may have been removed. Refresh the page and try again.'}
Has anyone else gotten this?

@xidios
Copy link

xidios commented Jan 20, 2024

Fixing the code for cookies as described above does not work for me. Using buy_item method i get response: {'message': 'There was a problem purchasing your item. The listing may have been removed. Refresh the page and try again.'} Has anyone else gotten this?

Try to replace in buy_item method

data = {
            'sessionid': self._session_id,
            'currency': currency.value,
            'subtotal': price - fee,
            'fee': fee,
            'total': price,
            'quantity': '1',
        }

with

data = {
            'sessionid': self._session.cookies.get_dict("steamcommunity.com")['sessionid'],
            'currency': currency.value,
            'subtotal': price - fee,
            'fee': fee,
            'total': price,
            'quantity': '1',
        }

@StarOneButterfly
Copy link

Fixing the code for cookies as described above does not work for me. Using buy_item method i get response: {'message': 'There was a problem purchasing your item. The listing may have been removed. Refresh the page and try again.'} Has anyone else gotten this?

Try to replace in buy_item method

data = {
            'sessionid': self._session_id,
            'currency': currency.value,
            'subtotal': price - fee,
            'fee': fee,
            'total': price,
            'quantity': '1',
        }

with

data = {
            'sessionid': self._session.cookies.get_dict("steamcommunity.com")['sessionid'],
            'currency': currency.value,
            'subtotal': price - fee,
            'fee': fee,
            'total': price,
            'quantity': '1',
        }

it doesn't help, I also get an error: There was a problem purchasing your item. The listing may have been removed. Refresh the page and try again

@lspeed-v
Copy link

Fixed code for cookies:

in 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)

in client.py (if you use accept trade offer function):

    @login_required
    def accept_trade_offer(self, trade_offer_id: str) -> dict:
        trade = self.get_trade_offer(trade_offer_id)
        trade_offer_state = TradeOfferState(trade['response']['offer']['trade_offer_state'])
        if trade_offer_state is not TradeOfferState.Active:
            raise ApiException(f'Invalid trade offer state: {trade_offer_state.name} ({trade_offer_state.value})')

        partner = self._fetch_trade_partner_id(trade_offer_id)
        session_id = self._session.cookies.get_dict("steamcommunity.com")['sessionid']
        accept_url = f'{SteamUrl.COMMUNITY_URL}/tradeoffer/{trade_offer_id}/accept'
        params = {
            'sessionid': session_id,
            'tradeofferid': trade_offer_id,
            'serverid': '1',
            'partner': partner,
            'captcha': '',
        }
        headers = {'Referer': self._get_trade_offer_url(trade_offer_id)}

        response = self._session.post(accept_url, data=params, headers=headers).json()
        if response.get('needs_mobile_confirmation', False):
            return self._confirm_transaction(trade_offer_id)

        return response

In general, if you need to restore the functionality of functions, then you need to check calls to self._session.cookies.get_dict and pass the required domain

I only tested the code for steamcommunity, so let me know if anything doesn't work

Seems everything works fine, thank you

@HappyWaffle566
Copy link

Had somebody found a solution to KeyError: 'refresh_token'?

@Dandelion101
Copy link

Had somebody found a solution to KeyError: 'refresh_token'?

The KeyError: 'refresh_token' exception occurs when you have exhausted all your login attempts. They are usually updated after 12 hours

Your question is not related to the topic of this question #343, next time create a new question

@HappyWaffle566
Copy link

Had somebody found a solution to KeyError: 'refresh_token'?

The KeyError: 'refresh_token' exception occurs when you have exhausted all your login attempts. They are usually updated after 12 hours

Your question is not related to the topic of this question #343, next time create a new question

Oh, I see. I'm sorry. The problem has appeared since the library broke and cookies seemed to be broken (I get refresh_token error when I try to set cookies). Sorry for troubling

@Aarab228
Copy link

I updated the login.py file to the above commit from @xidios but authorization still doesn't work as well as purchases in steam)
Does anyone know what this is related to? Every time I try to log in to my account cookies are created, and when I try to log in again authorization via cookies doesn't work with the error "Invalid steam_id: None".

@SiSiska
Copy link

SiSiska commented Feb 17, 2024

client.py

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests