Skip to content

Commit

Permalink
Minor 1.4.6
Browse files Browse the repository at this point in the history
Added valid API key check.
Added Assertion error at 402 error.
  • Loading branch information
vulnersCom committed Mar 20, 2019
1 parent 4e82e05 commit 0442fec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vulners/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

__version__ = "1.4.5"
__version__ = "1.4.6"

from vulners.api import Vulners
4 changes: 4 additions & 0 deletions vulners/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down

0 comments on commit 0442fec

Please sign in to comment.