From 1ffb0a97c0ca15721042590deadf3d2754094aec Mon Sep 17 00:00:00 2001 From: Ivan Popov Date: Mon, 23 Sep 2024 23:33:59 +0300 Subject: [PATCH] fix modeus bug --- backend/integration/modeus.py | 17 +++++----- backend/poetry.lock | 60 ++++++++++++++--------------------- backend/pyproject.toml | 2 +- 3 files changed, 33 insertions(+), 46 deletions(-) diff --git a/backend/integration/modeus.py b/backend/integration/modeus.py index aa56f40..8db936d 100644 --- a/backend/integration/modeus.py +++ b/backend/integration/modeus.py @@ -32,7 +32,7 @@ async def get_post_url(session: AsyncClient, token_length: int = 16) -> URL: "nonce": token_hex(token_length), "state": token_hex(token_length), } - response = await session.get(auth_url, params=auth_data) + response = await session.get(auth_url, params=auth_data, follow_redirects=True) # response.raise_for_status() post_url = response.url if post_url is None: @@ -54,7 +54,7 @@ async def get_auth_form(session: AsyncClient, username: str, password: str) -> T "Password": password, "AuthMethod": "FormsAuthentication", } - response = await session.post(post_url, data=login_data) + response = await session.post(post_url, data=login_data, follow_redirects=True) # response.raise_for_status() html_text = response.text @@ -76,12 +76,11 @@ async def login(username: str, __password: str, timeout: int = 15) -> Dict[str, Raises: CannotAuthenticateError: if something changed in API """ - session = AsyncClient( - http2=True, - base_url="https://utmn.modeus.org/", - timeout=timeout, - ) - + # with AsyncClient(http2=True, base_url="https://utmn.modeus.org/", timeout=timeout,) as session: + # pass + session = AsyncClient(http2=True, base_url="https://utmn.modeus.org/", timeout=timeout, headers={ + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0', + }, follow_redirects=True,) form = await get_auth_form(session, username, __password) auth_data = {} continue_auth_url = "https://auth.modeus.org/commonauth" @@ -90,7 +89,7 @@ async def login(username: str, __password: str, timeout: int = 15) -> Dict[str, response = await session.post( continue_auth_url, data=auth_data, - allow_redirects=False, + follow_redirects=False, ) headers = {"Referer": "https://fs.utmn.ru/"} auth_id = response.cookies.get("commonAuthId") diff --git a/backend/poetry.lock b/backend/poetry.lock index 58708ec..2a657e9 100644 --- a/backend/poetry.lock +++ b/backend/poetry.lock @@ -874,13 +874,13 @@ jwt = ["cryptography", "pyjwt"] [[package]] name = "h11" -version = "0.12.0" +version = "0.14.0" description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" files = [ - {file = "h11-0.12.0-py3-none-any.whl", hash = "sha256:36a3cb8c0a032f56e2da7084577878a035d3b61d104230d4bd49c0c6b555a9c6"}, - {file = "h11-0.12.0.tar.gz", hash = "sha256:47222cb6067e4a307d535814917cd98fd0a57b6788ce715755fa2b6c28b56042"}, + {file = "h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"}, + {file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"}, ] [[package]] @@ -911,22 +911,24 @@ files = [ [[package]] name = "httpcore" -version = "0.13.7" +version = "1.0.5" description = "A minimal low-level HTTP client." optional = false -python-versions = ">=3.6" +python-versions = ">=3.8" files = [ - {file = "httpcore-0.13.7-py3-none-any.whl", hash = "sha256:369aa481b014cf046f7067fddd67d00560f2f00426e79569d99cb11245134af0"}, - {file = "httpcore-0.13.7.tar.gz", hash = "sha256:036f960468759e633574d7c121afba48af6419615d36ab8ede979f1ad6276fa3"}, + {file = "httpcore-1.0.5-py3-none-any.whl", hash = "sha256:421f18bac248b25d310f3cacd198d55b8e6125c107797b609ff9b7a6ba7991b5"}, + {file = "httpcore-1.0.5.tar.gz", hash = "sha256:34a38e2f9291467ee3b44e89dd52615370e152954ba21721378a87b2960f7a61"}, ] [package.dependencies] -anyio = "==3.*" -h11 = ">=0.11,<0.13" -sniffio = "==1.*" +certifi = "*" +h11 = ">=0.13,<0.15" [package.extras] +asyncio = ["anyio (>=4.0,<5.0)"] http2 = ["h2 (>=3,<5)"] +socks = ["socksio (==1.*)"] +trio = ["trio (>=0.22.0,<0.26.0)"] [[package]] name = "httptools" @@ -978,26 +980,29 @@ test = ["Cython (>=0.29.24,<0.30.0)"] [[package]] name = "httpx" -version = "0.19.0" +version = "0.27.2" description = "The next generation HTTP client." optional = false -python-versions = ">=3.6" +python-versions = ">=3.8" files = [ - {file = "httpx-0.19.0-py3-none-any.whl", hash = "sha256:9bd728a6c5ec0a9e243932a9983d57d3cc4a87bb4f554e1360fce407f78f9435"}, - {file = "httpx-0.19.0.tar.gz", hash = "sha256:92ecd2c00c688b529eda11cedb15161eaf02dee9116712f621c70d9a40b2cdd0"}, + {file = "httpx-0.27.2-py3-none-any.whl", hash = "sha256:7bb2708e112d8fdd7829cd4243970f0c223274051cb35ee80c03301ee29a3df0"}, + {file = "httpx-0.27.2.tar.gz", hash = "sha256:f7c2be1d2f3c3c3160d441802406b206c2b76f5947b11115e6df10c6c65e66c2"}, ] [package.dependencies] +anyio = "*" certifi = "*" -charset-normalizer = "*" h2 = {version = ">=3,<5", optional = true, markers = "extra == \"http2\""} -httpcore = ">=0.13.3,<0.14.0" -rfc3986 = {version = ">=1.3,<2", extras = ["idna2008"]} +httpcore = "==1.*" +idna = "*" sniffio = "*" [package.extras] brotli = ["brotli", "brotlicffi"] +cli = ["click (==8.*)", "pygments (==2.*)", "rich (>=10,<14)"] http2 = ["h2 (>=3,<5)"] +socks = ["socksio (==1.*)"] +zstd = ["zstandard (>=0.18.0)"] [[package]] name = "hyperframe" @@ -1933,23 +1938,6 @@ files = [ [package.dependencies] docutils = ">=0.11,<1.0" -[[package]] -name = "rfc3986" -version = "1.5.0" -description = "Validating URI References per RFC 3986" -optional = false -python-versions = "*" -files = [ - {file = "rfc3986-1.5.0-py2.py3-none-any.whl", hash = "sha256:a86d6e1f5b1dc238b218b012df0aa79409667bb209e58da56d0b94704e712a97"}, - {file = "rfc3986-1.5.0.tar.gz", hash = "sha256:270aaf10d87d0d4e095063c65bf3ddbc6ee3d0b226328ce21e036f946e421835"}, -] - -[package.dependencies] -idna = {version = "*", optional = true, markers = "extra == \"idna2008\""} - -[package.extras] -idna2008 = ["idna"] - [[package]] name = "rich" version = "13.8.1" @@ -2434,4 +2422,4 @@ h11 = ">=0.9.0,<1" [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "d2655da41614a87564053780be646000b43675d2a472c656c48b2058f31d14f1" +content-hash = "5358449b80280d90765e16ac734d27e0b0ea272fca75b481b3f269cb2ffcfd30" diff --git a/backend/pyproject.toml b/backend/pyproject.toml index b5f2e33..16a53ff 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -12,7 +12,7 @@ requests = "^2.32.3" undetected-chromedriver = "^3.5.5" environs = "^11.0.0" jwt = "^1.3.1" -httpx = {version = ">=0.19.0,<0.20.0", extras = ["http2"]} +httpx = {version = ">=0.19.0", extras = ["http2"]} beautifulsoup4 = ">=4.10.0,<4.11.0" blacksheep = {version = ">=2.0.0,<2.1.0", extras = ["full"]} blacksheep-cli = "^0.0.4"