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

accept_trade_offer isn't working #385

Open
lspeed-v opened this issue Apr 5, 2024 · 7 comments
Open

accept_trade_offer isn't working #385

lspeed-v opened this issue Apr 5, 2024 · 7 comments

Comments

@lspeed-v
Copy link

lspeed-v commented Apr 5, 2024

When I use this method an exception occurs with text: 'offer'.

@lspeed-v
Copy link
Author

lspeed-v commented Apr 5, 2024

For fix it, you need to make this changes #382 (comment)

And after change this function

def get_trade_offer(self, trade_offer_id: str, merge: bool = True, use_webtoken=False) -> dict:

    params = {
        'key' if not use_webtoken else 'access_token': self._api_key if not use_webtoken else self._access_token,
        'tradeofferid': trade_offer_id,
        'language': 'english'}

    #params = {'key': self._api_key, 'tradeofferid': trade_offer_id, 'language': 'english'}
    response = self.api_call('GET', 'IEconService', 'GetTradeOffer', 'v1', params).json()

    if merge and 'descriptions' in response['response']:
        descriptions = {get_description_key(offer): offer for offer in response['response']['descriptions']}
        offer = response['response']['offer']
        response['response']['offer'] = merge_items_with_descriptions_from_offer(offer, descriptions)

    return response

And this function also:

def accept_trade_offer(self, trade_offer_id: str) -> dict:
    trade = self.get_trade_offer(trade_offer_id, use_webtoken=True)
    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

@SamuelKollar
Copy link

I changed the code the access_token part under login(), however I still face the same issue of KeyError: 'offer', the response form steam I get is {}, did you change anything else ?

@lspeed-v
Copy link
Author

lspeed-v commented Apr 6, 2024

I changed the code the access_token part under login(), however I still face the same issue of KeyError: 'offer', the response form steam I get is {}, did you change anything else ?

Yes, my upper comment is updated. Now it should work

@SamuelKollar
Copy link

Okay, I tried it and I am able to send a trade offer but I am not able to track the status of the offer, if it is accepted or not. get_trade_offer() returns empty json.

@Mystic8b
Copy link

Is this project dead? Are there any alternatives?

@bukson
Copy link
Owner

bukson commented May 29, 2024

Project is not dead. I do not actively develop it, but I still merge pull requests and maintain it. Please create a pr with desired changes that fixes things and I will gladly merge it.

@lspeed-v
Copy link
Author

Project is not dead. I do not actively develop it, but I still merge pull requests and maintain it. Please create a pr with desired changes that fixes things and I will gladly merge it.

Thanks to @maromalo he already collect every community fix in one pr.

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

4 participants