bukson / steampy

A Steam trading library for python 3
MIT License
577 stars 157 forks source link

accept_trade_offer isn't working #385

Open lspeed-v opened 7 months ago

lspeed-v commented 7 months ago

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

lspeed-v commented 7 months ago

For fix it, you need to make this changes https://github.com/bukson/steampy/issues/382#issuecomment-2036162567

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 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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 commented 6 months ago

Is this project dead? Are there any alternatives?

bukson commented 6 months ago

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 commented 3 months ago

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.