Skip to content

Commit 161b453

Browse files
committed
First crack at some basic logging around request/response process. Currently problematic queries are difficult to debug, this should make it easier.
1 parent 310e272 commit 161b453

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

shopify/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import sys
88
from six.moves import urllib
99
import six
10-
10+
import logging
1111
from shopify.collection import PaginatedCollection
1212
from pyactiveresource.collection import Collection
13+
log = logging.getLogger(__name__)
1314

1415
# Store the response from the last request in the connection object
1516

@@ -23,10 +24,14 @@ def __init__(self, site, user=None, password=None, timeout=None, format=formats.
2324
def _open(self, *args, **kwargs):
2425
self.response = None
2526
try:
27+
log.debug(f"Request: {args, kwargs}")
2628
self.response = super(ShopifyConnection, self)._open(*args, **kwargs)
29+
log.debug(f'Response {self.response}')
2730
except pyactiveresource.connection.ConnectionError as err:
2831
self.response = err.response
32+
log.exception(f"Exception with request: {args, kwargs}, Response: {self.response}")
2933
raise
34+
3035
return self.response
3136

3237

shopify/session.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from shopify.api_access import ApiAccess
1414
from shopify.api_version import ApiVersion, Release, Unstable
1515
import six
16+
import logging
17+
18+
log = logging.getLogger(__name__)
1619

1720

1821
class ValidationException(Exception):
@@ -71,10 +74,13 @@ def request_token(self, params):
7174
url = "https://%s/admin/oauth/access_token?" % self.url
7275
query_params = dict(client_id=self.api_key, client_secret=self.secret, code=code)
7376
request = urllib.request.Request(url, urllib.parse.urlencode(query_params).encode("utf-8"))
77+
log.debug(f"Request URL: {url}, query params: {query_params}")
7478
response = urllib.request.urlopen(request)
79+
logging.debug(f"Response: {response}")
7580

7681
if response.code == 200:
7782
json_payload = json.loads(response.read().decode("utf-8"))
83+
log.debug(f"Response: {json_payload}")
7884
self.token = json_payload["access_token"]
7985
self.access_scopes = json_payload["scope"]
8086

0 commit comments

Comments
 (0)