Skip to content

Commit 3f00e63

Browse files
committed
refactor: Fix response_hook error when logging request id
1 parent 8f4041e commit 3f00e63

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

botanalytics/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ BA_API_KEY=""
1717

1818
# Base URL for the Botanalytics REST API
1919
# This default should not be changed unless you are directed to do so.
20-
BA_BASE_URL="https://api.botanalytics.co"
20+
BA_BASE_URL="https://api.botanalytics.co/v2/"
2121

2222
# Global timeout for requests in milliseconds
2323
BA_REQUEST_TIMEOUT=30000

botanalytics/__init__.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import re
33
import sys
44
import json
5+
import toml
56
import base64
7+
import pathlib
68
import pkg_resources
79
import multiprocessing
810
from loguru import logger
@@ -15,20 +17,16 @@
1517
from requests.adapters import HTTPAdapter
1618
from concurrent.futures import ThreadPoolExecutor
1719

18-
if 'unittest' in sys.modules.keys():
1920

20-
import toml
21-
import pathlib
22-
23-
pyproject_text = pathlib.Path('pyproject.toml').read_text()
24-
pyproject_data = toml.loads(pyproject_text)
21+
pyproject_text = pathlib.Path('pyproject.toml').read_text()
22+
pyproject_data = toml.loads(pyproject_text)
2523

24+
if 'poetry' in pyproject_data['tool']:
2625
__version__ = pyproject_data['tool']['poetry']['version']
27-
2826
else:
29-
3027
__version__ = pkg_resources.get_distribution('botanalytics').version
3128

29+
3230
load_dotenv()
3331

3432
ip_middle_octet = u"(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5]))"
@@ -169,7 +167,7 @@ def __init__(self, debug=None, api_key=None, base_url=None, channel=None,
169167

170168
request_retry_limit = (default_request_retry_limit if os.getenv('BA_REQUEST_RETRY_LIMIT')
171169
is None else int(os.getenv('BA_REQUEST_RETRY_LIMIT'))) \
172-
if 'request_retry_limit' not in kwargs else kwargs['request_retry_limit']
170+
if 'request_retry_limit' not in kwargs else int(kwargs['request_retry_limit'])
173171

174172
request_timeout = (default_request_timeout if os.getenv('BA_REQUEST_TIMEOUT')
175173
is None else int(os.getenv('BA_REQUEST_TIMEOUT'))) \
@@ -274,7 +272,7 @@ def send_messages(self, messages=None):
274272

275273
headers['X-Botanalytics-Client-Version'] = __version__
276274

277-
self.http.post('/messages',
275+
self.http.post('messages',
278276
data=request_json,
279277
headers=headers,
280278
allow_redirects=False,
@@ -324,11 +322,12 @@ def response_hook(self, response, *args, **kwargs):
324322

325323
try:
326324

325+
327326
data = response.json()
328327

329328
# Log request ID if available
330329
if 'request_id' in data:
331-
logger.debug('Message(s) successfully sent with the request ID \'%s\'.' % data.request_id)
330+
logger.debug('Message(s) successfully sent with the request ID \'%s\'.' % data['request_id'])
332331

333332
except:
334333

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ python = ">=3.7,<3.10"
2929
requests = "^2.28.0"
3030
requests-toolbelt = "^0.9.1"
3131
python-dotenv = "^0.20.0"
32-
loguru = "^0.6.0"
32+
loguru = "^0.6.0"
33+
toml = "^0.10.0"

0 commit comments

Comments
 (0)