Skip to content

Commit

Permalink
Merge pull request #65 from green-api/sw-4280
Browse files Browse the repository at this point in the history
SW-4280 Set up a timeout for requests
  • Loading branch information
prostraction authored Sep 30, 2024
2 parents 1365e5b + 2c2b8ad commit 82b8d50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="whatsapp-api-client-python",
version="0.0.46",
version="0.0.47",
description=(
"This library helps you easily create"
" a Python application with WhatsApp API."
Expand Down
12 changes: 9 additions & 3 deletions whatsapp_api_client_python/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ def __init__(
debug_mode: bool = False,
raise_errors: bool = False,
host: str = "https://api.green-api.com",
media: str = "https://media.green-api.com"
media: str = "https://media.green-api.com",
host_timeout: float = 180, # sec per retry
media_timeout: float = 10800, # sec per retry
):
self.host = host
self.media = media
self.debug_mode = debug_mode
self.raise_errors = raise_errors

# Change default values in init() if required
self.host_timeout = host_timeout
self.media_timeout = media_timeout

self.idInstance = idInstance
self.apiTokenInstance = apiTokenInstance

Expand Down Expand Up @@ -75,11 +81,11 @@ def request(
try:
if not files:
response = self.session.request(
method=method, url=url, json=payload
method=method, url=url, json=payload, timeout=self.host_timeout
)
else:
response = self.session.request(
method=method, url=url, data=payload, files=files
method=method, url=url, data=payload, files=files, timeout=self.media_timeout
)
except Exception as error:
error_message = f"Request was failed with error: {error}."
Expand Down

0 comments on commit 82b8d50

Please sign in to comment.