Exception occurred cannot unpack non-iterable NoneType object
Mte90 opened this issue · comments
Daniele Scasciafratte commented
Command used packt-cli -g
Output in log
[ERROR] - Fetching JWT token failed!
[INFO] - Start grabbing ebook...
[ERROR] - Exception occurred cannot unpack non-iterable NoneType object
mjenczmyk commented
You failed to log into Packt API - are you sure your credentials in configuration file are correct?
Daniele Scasciafratte commented
You were right, maybe add a better error can be more helpful for the next one :-D
mjenczmyk commented
We could exit from the script when fetching JWT fails, so the script doesn't break on confusing error (see diff below). What do you think?
diff --git a/src/api.py b/src/api.py
index 25be796..6576e02 100644
--- a/src/api.py
+++ b/src/api.py
@@ -1,5 +1,6 @@
"""Module with Packt API client handling API's authentication."""
import logging
+import sys
import requests
@@ -38,6 +39,7 @@ class PacktAPIClient:
logger.info('JWT token has been fetched successfully!')
except Exception:
logger.error('Fetching JWT token failed!')
+ sys.exit(1)
def request(self, method, url, **kwargs):
"""Make a request to a Packt API."""
Daniele Scasciafratte commented
seems a good idea but maybe add in the error also: "check your login settings before try again" can be helpful.