_fetch_trade_partner_id ValueError: substring not found.
I am writing an auto-acceptance of trades, I encountered a problem start = text.index(begin) + len(begin) ^^^^^^^^^^^^^^^^^ ValueError: substring not found Something is wrong in this function: def text_between(text: str, begin: str, end: str) -> str start = text.index(begin) + len(begin) end = text.index(end, start) return text[start:end] I just can't understand what the error is. Here is what I have written:
@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
def _fetch_trade_partner_id(self, trade_offer_id: str) -> str:
url = self._get_trade_offer_url(trade_offer_id)
offer_response_text = self._session.get(url).text
if 'You have logged in from a new device. In order to protect the items' in offer_response_text:
raise SevenDaysHoldException("Account has logged in a new device and can't trade for 7 days")
return text_between(offer_response_text, "var g_ulTradePartnerSteamID = '", "';")
Couldn't fix it? I have the same problem. I looked at the request I received from steam in the browser and it turned out that even though I was logged in, steam did not identify me as an authorized user.
I investigated the issue. This error happens when you’ve made too many requests to Steam. How to check it?
Go to steam profile page Log in in your account (if not logged) try to open inventory page (on the same ip (proxy) where “substring error” happens. If you see, error page “too many requests” so this error will happen. So why it happens? Because of: Fast re-checking your trade list Many requests trough SDA or any other software for auto-confirming. SIH may trigger this error. How to solve this problem? Turn off any software which communicates with your Steam profile for a while ( 24h may be), and try again.
Thats it.
the real problem is that changing IP address doesn't always work. you can change like 4-5 IPs before steam starts accepting your requests again