Skip to content

Commit

Permalink
RateLimitExceeded exception in get_item_name_id method. `buy_mark…
Browse files Browse the repository at this point in the history
…et_listing` will no longer raise `ClientResponseError`, `EResultError` better print output, updated LICENSE. v0.7.2
  • Loading branch information
somespecialone committed Jan 18, 2025
1 parent eec4bfb commit 977ec4c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2022-2024 Dmytro Tkachenko
Copyright (c) 2022-2025 Dmytro Tkachenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions aiosteampy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ async def prepare(self, api_key_domain: str = None, *, force=False):
"""
Prepares client to work by loading main attributes (trade token, currency and country, optionally api key)
from `Steam`. Register trade token and api key (optionally) if there is none.
Edit privacy settings of inventory and related staff to be public
:param api_key_domain: domain to register `Steam Web Api` key.
If not passed, api key will not be fetched and registered.
Expand Down
7 changes: 7 additions & 0 deletions aiosteampy/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def __init__(self, msg: str, result: EResult, data=None):
self.result = result
self.data = data

def __str__(self):
return self.msg


class LoginError(SteamError):
"""Raised when a problem with login process occurred"""
Expand All @@ -33,3 +36,7 @@ class ResourceNotModified(SteamError):
Special case when `If-Modified-Since` header included
in request headers and Steam response with 304 status code
"""


# class InsufficientBalance(SteamError):
# """"""
11 changes: 9 additions & 2 deletions aiosteampy/mixins/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,12 +868,19 @@ async def buy_market_listing(
**payload,
}
headers = {"Referer": str(STEAM_URL.MARKET / f"listings/{app.value}/{market_hash_name}"), **headers}
r = await self.session.post(STEAM_URL.MARKET / f"buylisting/{listing_id}", data=data, headers=headers)
r = await self.session.post(
STEAM_URL.MARKET / f"buylisting/{listing_id}",
data=data,
headers=headers,
raise_for_status=False,
)
# ClientResponseError with code 502 [Bad Gateway] will be raised in case of insufficient balance, need
# to do something with this somehow ...
rj: dict[str, dict[str, str]] = await r.json()
wallet_info: WalletInfo = rj.get("wallet_info", {})
success = EResult(wallet_info.get("success"))
if success is not EResult.OK:
raise EResultError(wallet_info.get("message", "Failed to buy listing"), success, rj)
raise EResultError(rj.get("message", wallet_info.get("message", "Failed to buy listing")), success, rj)

# how about to return remaining balance only?
return wallet_info
Expand Down
10 changes: 9 additions & 1 deletion aiosteampy/mixins/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ async def get_item_name_id(self, obj: str | ItemDescription, app: App = None, *,
:param app:
:param headers: extra headers to send with request
:return: `item_nameid`
:raises RateLimitExceeded: when you hit rate limit
.. seealso:: https://github.com/somespecialone/steam-item-name-ids
"""
Expand All @@ -891,7 +892,14 @@ async def get_item_name_id(self, obj: str | ItemDescription, app: App = None, *,
else: # str
url = STEAM_URL.MARKET / f"listings/{app.value}/{obj}"

res = await self.session.get(url, headers=headers)
try:
res = await self.session.get(url, headers=headers)
except ClientResponseError as e:
if e.status == 429:
raise RateLimitExceeded("You have been rate limited, rest for a while!") from e
else:
raise e

text = await res.text()

return find_item_nameid_in_text(text)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aiosteampy"
version = "0.7.1"
version = "0.7.2"
description = "Trade and interact with steam market, webapi, guard"
license = "MIT"
authors = ["Dmytro Tkachenko <[email protected]>"]
Expand Down

0 comments on commit 977ec4c

Please sign in to comment.