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

Add proxy support #17

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ async def main():
await steam.login_to_steam()
```

## Proxy usage

The library supports the usage of HTTP/HTTPS proxies.

```python
from pysteamauth.auth import Steam

async def main():
steam = Steam(
login='login',
password='password',
proxy="http://ip:port"
)

await steam.login_to_steam()
```

## Error processing

```python
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"
4 changes: 3 additions & 1 deletion pysteamauth/auth/steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ def __init__(
device_id: Optional[str] = None,
cookie_storage: Optional[CookieStorageAbstract] = None,
request_strategy: Optional[RequestStrategyAbstract] = None,
proxy: Optional[str] = None,
):
self._login = login
self._steamid = steamid
self._password = password
self._shared_secret = shared_secret
self._identity_secret = identity_secret
self._device_id = device_id
self._requests = request_strategy if request_strategy is not None else BaseRequestStrategy()
self._requests = request_strategy if request_strategy is not None else BaseRequestStrategy(proxy)
self._storage = cookie_storage if cookie_storage is not None else BaseCookieStorage()
self._proxy = proxy

@property
def steamid(self) -> int:
Expand Down
5 changes: 3 additions & 2 deletions pysteamauth/base/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

class BaseRequestStrategy(RequestStrategyAbstract):

def __init__(self):
def __init__(self, proxy: Optional[str] = None):
self._session: Optional[ClientSession] = None
self._proxy = proxy

def __del__(self):
if self._session:
Expand All @@ -37,7 +38,7 @@ def _create_session(self) -> ClientSession:
async def request(self, url: str, method: str, **kwargs: Any) -> ClientResponse:
if self._session is None:
self._session = self._create_session()
response = await self._session.request(method, url, **kwargs)
response = await self._session.request(method, url, proxy=self._proxy, **kwargs)
error = response.headers.get('X-eresult')
if error:
check_steam_error(int(error))
Expand Down
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import setuptools
from setuptools import setup


requirements = [
'aiohttp==3.10.2',
'protobuf==5.28.2',
Expand All @@ -11,7 +10,6 @@
'urllib3==2.2.2',
]


setup(
name='pysteamauth',
version='1.1.0',
Expand All @@ -26,6 +24,5 @@
zip_safe=False,
python_requires='>=3.9',
install_requires=requirements,
setup_requires=requirements,
include_package_data=True,
)