Added try except block to catch ssl errors. (#74)

If IGNORE_SSL_ERRORS is true, then silence SSL verification & continue.
If IGNORE_SSL_ERRORS is false, then raise the error with custom message.
Added verbose option to assist with reducing output and allowing for verbose logging if desired.
If IGNORE_SSL_ERRORS is false, and --verbose is specified, then print the exception.
This commit is contained in:
Daniel W. Anner 2023-03-03 12:25:25 -05:00 committed by GitHub
parent 3726326225
commit 1345a9d89e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 16 deletions

3
.gitignore vendored
View File

@ -102,7 +102,8 @@ celerybeat.pid
*.sage.py
# Environments
.env
.env*
!.env.example
.venv
env/
venv/

View File

@ -10,6 +10,7 @@ import os
import settings
import sys
import re
import requests
counter = Counter(
@ -768,21 +769,7 @@ def main():
cwd = os.getcwd()
startTime = datetime.now()
nbUrl = settings.NETBOX_URL
nbToken = settings.NETBOX_TOKEN
nb = pynetbox.api(nbUrl, token=nbToken)
determine_features(nb)
if settings.IGNORE_SSL_ERRORS:
import requests
requests.packages.urllib3.disable_warnings()
session = requests.Session()
session.verify = False
nb.http_session = session
VENDORS = settings.VENDORS
REPO_URL = settings.REPO_URL
@ -798,8 +785,27 @@ def main():
help="List of device-type slugs to import eg. ap4431 ws-c3850-24t-l")
parser.add_argument('--branch', default=REPO_BRANCH,
help="Git branch to use from repo")
parser.add_argument('--verbose', action='store_true',
help="Print verbose output")
args = parser.parse_args()
nbUrl = settings.NETBOX_URL
nbToken = settings.NETBOX_TOKEN
nb = pynetbox.api(nbUrl, token=nbToken)
try:
determine_features(nb)
except requests.exceptions.SSLError as e:
if args.verbose:
print(e)
if not settings.IGNORE_SSL_ERRORS:
print("IGNORE_SSL_ERRORS is False. SSL verification failed, exiting.")
sys.exit(1)
print("IGNORE_SSL_ERRORS is True, catching exception and disabling SSL verification.")
requests.packages.urllib3.disable_warnings()
nb.http_session.verify = False
determine_features(nb)
try:
if os.path.isdir('./repo'):
print(f"Package devicetype-library is already installed, "