Skip to content

Commit

Permalink
🚑 Fix: create a new session instead of passed, proxy property. v0…
Browse files Browse the repository at this point in the history
….6.2
  • Loading branch information
somespecialone committed Aug 25, 2024
1 parent 77ddb4a commit 447e468
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
20 changes: 11 additions & 9 deletions aiosteampy/mixins/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _session_helper(session: ClientSession = None, proxy: str = None) -> ClientS
raise TypeError(
"""
To use `socks` type proxies you need `aiohttp_socks` package.
You can do this with `aiosteampy[socks]` dependency install target.
You can do this with `aiosteampy[socks]` or `aiosteampy[all]` dependency install targets.
"""
)

Expand All @@ -137,24 +137,26 @@ def _session_helper(session: ClientSession = None, proxy: str = None) -> ClientS

session = patch_session_with_http_proxy(ClientSession(raise_for_status=True), proxy)

elif session and not session._raise_for_status:
warn(
"A session instance must be created with `raise_for_status=True` for client to work properly",
category=UserWarning,
)
else:
elif session:
if not session._raise_for_status:
warn(
"A session instance must be created with `raise_for_status=True` for client to work properly",
category=UserWarning,
)
else: # nothing passed
session = ClientSession(raise_for_status=True)

return session

# _proxy attr will be much easier, straight and less error-prone, why I need this?
@property
def proxy(self) -> str | None:
"""Proxy url in format `scheme://username:password@host:port` or `scheme://host:port`"""

if isinstance(self.session.connector, ProxyConnector): # socks
if isinstance(self.session.connector, ProxyConnector or int): # socks, int to avoid TypeError if None
c: ProxyConnector = self.session.connector

scheme = str(c._proxy_type).lower()
scheme = str(c._proxy_type.name).lower()
username = c._proxy_username
password = c._proxy_password
host = c._proxy_host
Expand Down
19 changes: 12 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aiosteampy"
version = "0.6.1"
version = "0.6.2"
description = "Trade and interact with steam market, webapi, guard"
license = "MIT"
authors = ["Dmytro Tkachenko <[email protected]>"]
Expand Down Expand Up @@ -38,9 +38,9 @@ packages = [{ include = "aiosteampy" }]
python = "^3.10"
aiohttp = "^3.8"
rsa = "^4.8"
aenum = ">=3.1.2, <4"
croniter = { version = ">=2, <4", optional = true }
aiohttp-socks = { version = ">=0.8.4, <1", optional = true }
aenum = ">=3.1.2, <4.0.0"
croniter = { version = ">=2.0, <4.0", optional = true }
aiohttp-socks = { version = ">=0.8.4, <1.0.0", optional = true }

[tool.poetry.extras]
converter = ["croniter"]
Expand Down

0 comments on commit 447e468

Please sign in to comment.