From 0442fec132d78ef4e829b1c229728b2395261f09 Mon Sep 17 00:00:00 2001 From: isox Date: Wed, 20 Mar 2019 21:21:16 +0300 Subject: [PATCH] Minor 1.4.6 Added valid API key check. Added Assertion error at 402 error. --- vulners/__init__.py | 2 +- vulners/api.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/vulners/__init__.py b/vulners/__init__.py index 49d40a0..6fd00fc 100644 --- a/vulners/__init__.py +++ b/vulners/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -__version__ = "1.4.5" +__version__ = "1.4.6" from vulners.api import Vulners diff --git a/vulners/api.py b/vulners/api.py index bb6e4e0..b6f27ae 100644 --- a/vulners/api.py +++ b/vulners/api.py @@ -105,10 +105,14 @@ def __init__(self, api_key = None, proxies=None, persistent=True): def __adapt_response_content(self, response): """ Check if response is a JSON and return it. Otherwise - return raw content + Also check 402 + 9000 response from backend: API key is invalid :param response: Requests response :return: {} or raw content """ + if response.status_code == 402 and response.json()['data']['errorCode'] == 9000: + raise AssertionError("Bad or no API key provided. Please, obtain correct one registering at https://vulners.com") + if re.match('.*json.*', response.headers.get('content-type'), re.IGNORECASE): results = response.json().get('data') if results.get('error'):