From 654d0ccde127bbc92d36c3b774978b3823191a28 Mon Sep 17 00:00:00 2001 From: AbdelrhmanNile Date: Mon, 5 Sep 2022 14:11:02 +0200 Subject: [PATCH] fix api not valid if limit reached --- freenlpc/freenlpc.py | 6 ++++-- setup.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/freenlpc/freenlpc.py b/freenlpc/freenlpc.py index a1fb8f7..c6685a8 100644 --- a/freenlpc/freenlpc.py +++ b/freenlpc/freenlpc.py @@ -40,8 +40,10 @@ def __check_keys(self): try: nlpcloud.Client(self.which_model("sentiment_pos_neg"), self.__api_keys[i], lang="en").sentiment("i hate physics") - except requests.exceptions.HTTPError: - raise Exception(f"API Token at index {i} is not valid.") + except requests.exceptions.HTTPError as e: + if str(e).find("Unauthorized") != -1: + raise Exception( + f"API Token at index {i} is not valid.") def which_model(self, task_name): """which model is being used for a specific task. diff --git a/setup.py b/setup.py index d6574df..c0f9071 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -VERSION = '0.1.6' +VERSION = '0.1.7' DESCRIPTION = 'A wrapper for nlpcloud free-tier services with no requests per minute limits.' LONG_DESCRIPTION = """# freenlpc a wrapper for nlpcloud free-tier.