From 23cc332a4f372bb659cc260d688073c51cd0f64f Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 16 Aug 2024 12:40:26 +0530 Subject: [PATCH 1/2] fix: timeout (#522) * fix: timeout * fix: timeout --- CHANGELOG.md | 4 ++++ setup.py | 2 +- supertokens_python/constants.py | 2 +- supertokens_python/querier.py | 2 +- supertokens_python/recipe/dashboard/api/analytics.py | 2 +- .../emaildelivery/services/backward_compatibility/__init__.py | 2 +- .../emaildelivery/services/backward_compatibility/__init__.py | 2 +- .../emaildelivery/services/backward_compatibility/__init__.py | 2 +- .../smsdelivery/services/backward_compatibility/__init__.py | 2 +- .../passwordless/smsdelivery/services/supertokens/__init__.py | 2 +- supertokens_python/recipe/thirdparty/providers/custom.py | 2 +- supertokens_python/recipe/thirdparty/providers/utils.py | 4 ++-- 12 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44d8edaf4..04e549b0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +## [0.24.1] - 2024-08-16 + +- Sets time out for httpx client to 30s everywhere. - https://github.com/supertokens/supertokens-python/issues/516 + ## [0.24.0] - 2024-07-31 ### Changes diff --git a/setup.py b/setup.py index 4b3896190..9a896818f 100644 --- a/setup.py +++ b/setup.py @@ -83,7 +83,7 @@ setup( name="supertokens_python", - version="0.24.0", + version="0.24.1", author="SuperTokens", license="Apache 2.0", author_email="team@supertokens.com", diff --git a/supertokens_python/constants.py b/supertokens_python/constants.py index f7e60529a..2f3242fa9 100644 --- a/supertokens_python/constants.py +++ b/supertokens_python/constants.py @@ -14,7 +14,7 @@ from __future__ import annotations SUPPORTED_CDI_VERSIONS = ["3.0"] -VERSION = "0.24.0" +VERSION = "0.24.1" TELEMETRY = "/telemetry" USER_COUNT = "/users/count" USER_DELETE = "/user/remove" diff --git a/supertokens_python/querier.py b/supertokens_python/querier.py index be1278b86..6382f4cd1 100644 --- a/supertokens_python/querier.py +++ b/supertokens_python/querier.py @@ -106,7 +106,7 @@ async def api_request( raise Exception("Retry request failed") try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: if method == "GET": return await client.get(url, *args, **kwargs) # type: ignore if method == "POST": diff --git a/supertokens_python/recipe/dashboard/api/analytics.py b/supertokens_python/recipe/dashboard/api/analytics.py index e5faba3a9..420b9f99f 100644 --- a/supertokens_python/recipe/dashboard/api/analytics.py +++ b/supertokens_python/recipe/dashboard/api/analytics.py @@ -93,7 +93,7 @@ async def handle_analytics_post( data["telemetryId"] = telemetry_id try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: await client.post( # type: ignore url=TELEMETRY_SUPERTOKENS_API_URL, json=data, diff --git a/supertokens_python/recipe/emailpassword/emaildelivery/services/backward_compatibility/__init__.py b/supertokens_python/recipe/emailpassword/emaildelivery/services/backward_compatibility/__init__.py index 3fb2a7789..ee295789e 100644 --- a/supertokens_python/recipe/emailpassword/emaildelivery/services/backward_compatibility/__init__.py +++ b/supertokens_python/recipe/emailpassword/emaildelivery/services/backward_compatibility/__init__.py @@ -41,7 +41,7 @@ async def create_and_send_email_using_supertokens_service( "passwordResetURL": password_reset_url_with_token, } try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: resp = await client.post("https://api.supertokens.io/0/st/auth/password/reset", json=data, headers={"api-version": "0"}) # type: ignore resp.raise_for_status() log_debug_message("Password reset email sent to %s", user.email) diff --git a/supertokens_python/recipe/emailverification/emaildelivery/services/backward_compatibility/__init__.py b/supertokens_python/recipe/emailverification/emaildelivery/services/backward_compatibility/__init__.py index b78891e3f..128cef084 100644 --- a/supertokens_python/recipe/emailverification/emaildelivery/services/backward_compatibility/__init__.py +++ b/supertokens_python/recipe/emailverification/emaildelivery/services/backward_compatibility/__init__.py @@ -38,7 +38,7 @@ async def create_and_send_email_using_supertokens_service( "emailVerifyURL": email_verification_url, } try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: resp = await client.post("https://api.supertokens.io/0/st/auth/email/verify", json=data, headers={"api-version": "0"}) # type: ignore resp.raise_for_status() log_debug_message("Email verification email sent to %s", user.email) diff --git a/supertokens_python/recipe/passwordless/emaildelivery/services/backward_compatibility/__init__.py b/supertokens_python/recipe/passwordless/emaildelivery/services/backward_compatibility/__init__.py index 630adc2d1..d4b274a75 100644 --- a/supertokens_python/recipe/passwordless/emaildelivery/services/backward_compatibility/__init__.py +++ b/supertokens_python/recipe/passwordless/emaildelivery/services/backward_compatibility/__init__.py @@ -45,7 +45,7 @@ async def create_and_send_email_with_supertokens_service( data["userInputCode"] = input_.user_input_code try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: resp = await client.post("https://api.supertokens.io/0/st/auth/passwordless/login", json=data, headers={"api-version": "0"}) # type: ignore resp.raise_for_status() log_debug_message("Passwordless login email sent to %s", input_.email) diff --git a/supertokens_python/recipe/passwordless/smsdelivery/services/backward_compatibility/__init__.py b/supertokens_python/recipe/passwordless/smsdelivery/services/backward_compatibility/__init__.py index 8b79ccbea..9129da29d 100644 --- a/supertokens_python/recipe/passwordless/smsdelivery/services/backward_compatibility/__init__.py +++ b/supertokens_python/recipe/passwordless/smsdelivery/services/backward_compatibility/__init__.py @@ -46,7 +46,7 @@ async def create_and_send_sms_using_supertokens_service( sms_input_json["urlWithLinkCode"] = input_.url_with_link_code try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: res = await client.post( # type: ignore SUPERTOKENS_SMS_SERVICE_URL, json={ diff --git a/supertokens_python/recipe/passwordless/smsdelivery/services/supertokens/__init__.py b/supertokens_python/recipe/passwordless/smsdelivery/services/supertokens/__init__.py index a25be8d0e..09669357a 100644 --- a/supertokens_python/recipe/passwordless/smsdelivery/services/supertokens/__init__.py +++ b/supertokens_python/recipe/passwordless/smsdelivery/services/supertokens/__init__.py @@ -50,7 +50,7 @@ async def send_sms( if template_vars.user_input_code: sms_input["userInputCode"] = template_vars.user_input_code try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: await client.post( # type: ignore SUPERTOKENS_SMS_SERVICE_URL, json={ diff --git a/supertokens_python/recipe/thirdparty/providers/custom.py b/supertokens_python/recipe/thirdparty/providers/custom.py index 8da6de021..9b6a355de 100644 --- a/supertokens_python/recipe/thirdparty/providers/custom.py +++ b/supertokens_python/recipe/thirdparty/providers/custom.py @@ -156,7 +156,7 @@ async def verify_id_token_from_jwks_endpoint_and_get_payload( id_token: str, jwks_uri: str, audience: str ): public_keys: List[RSAAlgorithm] = [] - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: response = await client.get(jwks_uri) # type:ignore key_payload = response.json() for key in key_payload["keys"]: diff --git a/supertokens_python/recipe/thirdparty/providers/utils.py b/supertokens_python/recipe/thirdparty/providers/utils.py index 875b0118d..9f9aaf80b 100644 --- a/supertokens_python/recipe/thirdparty/providers/utils.py +++ b/supertokens_python/recipe/thirdparty/providers/utils.py @@ -36,7 +36,7 @@ async def do_get_request( if headers is None: headers = {} - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: res = await client.get(url, params=query_params, headers=headers) # type:ignore log_debug_message( @@ -59,7 +59,7 @@ async def do_post_request( headers["content-type"] = "application/x-www-form-urlencoded" headers["accept"] = "application/json" - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: res = await client.post(url, data=body_params, headers=headers) # type:ignore log_debug_message( "Received response with status %s and body %s", res.status_code, res.text From 41da84d5cc1100db97680c6bbce370adf59dc29b Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 16 Aug 2024 12:40:53 +0530 Subject: [PATCH 2/2] adding dev-v0.24.1 tag to this commit to ensure building --- html/supertokens_python/constants.html | 2 +- html/supertokens_python/querier.html | 6 +++--- .../recipe/dashboard/api/analytics.html | 4 ++-- html/supertokens_python/recipe/dashboard/api/index.html | 2 +- .../services/backward_compatibility/index.html | 4 ++-- .../services/backward_compatibility/index.html | 4 ++-- .../services/backward_compatibility/index.html | 4 ++-- .../services/backward_compatibility/index.html | 4 ++-- .../smsdelivery/services/supertokens/index.html | 6 +++--- .../recipe/thirdparty/providers/custom.html | 4 ++-- .../recipe/thirdparty/providers/utils.html | 8 ++++---- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/html/supertokens_python/constants.html b/html/supertokens_python/constants.html index f1785e7c4..091b6d136 100644 --- a/html/supertokens_python/constants.html +++ b/html/supertokens_python/constants.html @@ -42,7 +42,7 @@

Module supertokens_python.constants

from __future__ import annotations SUPPORTED_CDI_VERSIONS = ["3.0"] -VERSION = "0.24.0" +VERSION = "0.24.1" TELEMETRY = "/telemetry" USER_COUNT = "/users/count" USER_DELETE = "/user/remove" diff --git a/html/supertokens_python/querier.html b/html/supertokens_python/querier.html index eceb2815b..6b3b7a147 100644 --- a/html/supertokens_python/querier.html +++ b/html/supertokens_python/querier.html @@ -134,7 +134,7 @@

Module supertokens_python.querier

raise Exception("Retry request failed") try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: if method == "GET": return await client.get(url, *args, **kwargs) # type: ignore if method == "POST": @@ -658,7 +658,7 @@

Classes

raise Exception("Retry request failed") try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: if method == "GET": return await client.get(url, *args, **kwargs) # type: ignore if method == "POST": @@ -1234,7 +1234,7 @@

Methods

raise Exception("Retry request failed") try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: if method == "GET": return await client.get(url, *args, **kwargs) # type: ignore if method == "POST": diff --git a/html/supertokens_python/recipe/dashboard/api/analytics.html b/html/supertokens_python/recipe/dashboard/api/analytics.html index 6046692b0..61801cbf1 100644 --- a/html/supertokens_python/recipe/dashboard/api/analytics.html +++ b/html/supertokens_python/recipe/dashboard/api/analytics.html @@ -121,7 +121,7 @@

Module supertokens_python.recipe.dashboard.api.analytics data["telemetryId"] = telemetry_id try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: await client.post( # type: ignore url=TELEMETRY_SUPERTOKENS_API_URL, json=data, @@ -209,7 +209,7 @@

Functions

data["telemetryId"] = telemetry_id try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: await client.post( # type: ignore url=TELEMETRY_SUPERTOKENS_API_URL, json=data, diff --git a/html/supertokens_python/recipe/dashboard/api/index.html b/html/supertokens_python/recipe/dashboard/api/index.html index 29700182b..b64b53d69 100644 --- a/html/supertokens_python/recipe/dashboard/api/index.html +++ b/html/supertokens_python/recipe/dashboard/api/index.html @@ -252,7 +252,7 @@

Functions

data["telemetryId"] = telemetry_id try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: await client.post( # type: ignore url=TELEMETRY_SUPERTOKENS_API_URL, json=data, diff --git a/html/supertokens_python/recipe/emailpassword/emaildelivery/services/backward_compatibility/index.html b/html/supertokens_python/recipe/emailpassword/emaildelivery/services/backward_compatibility/index.html index e41ce3f3f..c05100626 100644 --- a/html/supertokens_python/recipe/emailpassword/emaildelivery/services/backward_compatibility/index.html +++ b/html/supertokens_python/recipe/emailpassword/emaildelivery/services/backward_compatibility/index.html @@ -69,7 +69,7 @@

Module supertokens_python.recipe.emailpassword.emaildeli "passwordResetURL": password_reset_url_with_token, } try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: resp = await client.post("https://api.supertokens.io/0/st/auth/password/reset", json=data, headers={"api-version": "0"}) # type: ignore resp.raise_for_status() log_debug_message("Password reset email sent to %s", user.email) @@ -140,7 +140,7 @@

Functions

"passwordResetURL": password_reset_url_with_token, } try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: resp = await client.post("https://api.supertokens.io/0/st/auth/password/reset", json=data, headers={"api-version": "0"}) # type: ignore resp.raise_for_status() log_debug_message("Password reset email sent to %s", user.email) diff --git a/html/supertokens_python/recipe/emailverification/emaildelivery/services/backward_compatibility/index.html b/html/supertokens_python/recipe/emailverification/emaildelivery/services/backward_compatibility/index.html index 8e8c20320..7c026ff1c 100644 --- a/html/supertokens_python/recipe/emailverification/emaildelivery/services/backward_compatibility/index.html +++ b/html/supertokens_python/recipe/emailverification/emaildelivery/services/backward_compatibility/index.html @@ -66,7 +66,7 @@

Module supertokens_python.recipe.emailverification.email "emailVerifyURL": email_verification_url, } try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: resp = await client.post("https://api.supertokens.io/0/st/auth/email/verify", json=data, headers={"api-version": "0"}) # type: ignore resp.raise_for_status() log_debug_message("Email verification email sent to %s", user.email) @@ -126,7 +126,7 @@

Functions

"emailVerifyURL": email_verification_url, } try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: resp = await client.post("https://api.supertokens.io/0/st/auth/email/verify", json=data, headers={"api-version": "0"}) # type: ignore resp.raise_for_status() log_debug_message("Email verification email sent to %s", user.email) diff --git a/html/supertokens_python/recipe/passwordless/emaildelivery/services/backward_compatibility/index.html b/html/supertokens_python/recipe/passwordless/emaildelivery/services/backward_compatibility/index.html index c1d1f4a16..e6be99a9f 100644 --- a/html/supertokens_python/recipe/passwordless/emaildelivery/services/backward_compatibility/index.html +++ b/html/supertokens_python/recipe/passwordless/emaildelivery/services/backward_compatibility/index.html @@ -73,7 +73,7 @@

Module supertokens_python.recipe.passwordless.emaildeliv data["userInputCode"] = input_.user_input_code try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: resp = await client.post("https://api.supertokens.io/0/st/auth/passwordless/login", json=data, headers={"api-version": "0"}) # type: ignore resp.raise_for_status() log_debug_message("Passwordless login email sent to %s", input_.email) @@ -145,7 +145,7 @@

Functions

data["userInputCode"] = input_.user_input_code try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: resp = await client.post("https://api.supertokens.io/0/st/auth/passwordless/login", json=data, headers={"api-version": "0"}) # type: ignore resp.raise_for_status() log_debug_message("Passwordless login email sent to %s", input_.email) diff --git a/html/supertokens_python/recipe/passwordless/smsdelivery/services/backward_compatibility/index.html b/html/supertokens_python/recipe/passwordless/smsdelivery/services/backward_compatibility/index.html index fe3de341e..822c8815e 100644 --- a/html/supertokens_python/recipe/passwordless/smsdelivery/services/backward_compatibility/index.html +++ b/html/supertokens_python/recipe/passwordless/smsdelivery/services/backward_compatibility/index.html @@ -74,7 +74,7 @@

Module supertokens_python.recipe.passwordless.smsdeliver sms_input_json["urlWithLinkCode"] = input_.url_with_link_code try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: res = await client.post( # type: ignore SUPERTOKENS_SMS_SERVICE_URL, json={ @@ -165,7 +165,7 @@

Functions

sms_input_json["urlWithLinkCode"] = input_.url_with_link_code try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: res = await client.post( # type: ignore SUPERTOKENS_SMS_SERVICE_URL, json={ diff --git a/html/supertokens_python/recipe/passwordless/smsdelivery/services/supertokens/index.html b/html/supertokens_python/recipe/passwordless/smsdelivery/services/supertokens/index.html index d091cea97..5ffaccf49 100644 --- a/html/supertokens_python/recipe/passwordless/smsdelivery/services/supertokens/index.html +++ b/html/supertokens_python/recipe/passwordless/smsdelivery/services/supertokens/index.html @@ -78,7 +78,7 @@

Module supertokens_python.recipe.passwordless.smsdeliver if template_vars.user_input_code: sms_input["userInputCode"] = template_vars.user_input_code try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: await client.post( # type: ignore SUPERTOKENS_SMS_SERVICE_URL, json={ @@ -136,7 +136,7 @@

Classes

if template_vars.user_input_code: sms_input["userInputCode"] = template_vars.user_input_code try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: await client.post( # type: ignore SUPERTOKENS_SMS_SERVICE_URL, json={ @@ -186,7 +186,7 @@

Methods

if template_vars.user_input_code: sms_input["userInputCode"] = template_vars.user_input_code try: - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: await client.post( # type: ignore SUPERTOKENS_SMS_SERVICE_URL, json={ diff --git a/html/supertokens_python/recipe/thirdparty/providers/custom.html b/html/supertokens_python/recipe/thirdparty/providers/custom.html index 082658610..a533be40f 100644 --- a/html/supertokens_python/recipe/thirdparty/providers/custom.html +++ b/html/supertokens_python/recipe/thirdparty/providers/custom.html @@ -184,7 +184,7 @@

Module supertokens_python.recipe.thirdparty.providers.cu id_token: str, jwks_uri: str, audience: str ): public_keys: List[RSAAlgorithm] = [] - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: response = await client.get(jwks_uri) # type:ignore key_payload = response.json() for key in key_payload["keys"]: @@ -695,7 +695,7 @@

Functions

id_token: str, jwks_uri: str, audience: str ): public_keys: List[RSAAlgorithm] = [] - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: response = await client.get(jwks_uri) # type:ignore key_payload = response.json() for key in key_payload["keys"]: diff --git a/html/supertokens_python/recipe/thirdparty/providers/utils.html b/html/supertokens_python/recipe/thirdparty/providers/utils.html index e8d015452..3655535d2 100644 --- a/html/supertokens_python/recipe/thirdparty/providers/utils.html +++ b/html/supertokens_python/recipe/thirdparty/providers/utils.html @@ -64,7 +64,7 @@

Module supertokens_python.recipe.thirdparty.providers.ut if headers is None: headers = {} - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: res = await client.get(url, params=query_params, headers=headers) # type:ignore log_debug_message( @@ -87,7 +87,7 @@

Module supertokens_python.recipe.thirdparty.providers.ut headers["content-type"] = "application/x-www-form-urlencoded" headers["accept"] = "application/json" - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: res = await client.post(url, data=body_params, headers=headers) # type:ignore log_debug_message( "Received response with status %s and body %s", res.status_code, res.text @@ -143,7 +143,7 @@

Functions

if headers is None: headers = {} - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: res = await client.get(url, params=query_params, headers=headers) # type:ignore log_debug_message( @@ -175,7 +175,7 @@

Functions

headers["content-type"] = "application/x-www-form-urlencoded" headers["accept"] = "application/json" - async with AsyncClient() as client: + async with AsyncClient(timeout=30.0) as client: res = await client.post(url, data=body_params, headers=headers) # type:ignore log_debug_message( "Received response with status %s and body %s", res.status_code, res.text