packt-cli / Packt-Publishing-Free-Learning

Scripts that automatically claim and download free daily eBooks from https://www.packtpub.com/packt/offers/free-learning

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception occurred cannot unpack non-iterable NoneType object

Mte90 opened this issue · comments

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

You failed to log into Packt API - are you sure your credentials in configuration file are correct?

You were right, maybe add a better error can be more helpful for the next one :-D

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."""

seems a good idea but maybe add in the error also: "check your login settings before try again" can be helpful.

See #150 if it looks right.