Created
November 2, 2018 14:37
-
-
Save SteveMcGrath/5aaf25d6a49afb316d90fb94ad192e0f to your computer and use it in GitHub Desktop.
Example connecting to Tenable.io w/o pyTenable or the Python SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from requests.packages.urllib3.util.retry import Retry | |
# Sets the retry adaptor with the ability to properly backoff if we get 429s | |
retries = Retry( | |
total=3, | |
status_forcelist={429, 501, 502, 503, 504}, | |
backoff_factor=1, | |
respect_retry_after_header=True | |
) | |
adapter = requests.adapters.HTTPAdapter(max_retries=retries) | |
# initiate the session and then attach the Retry adaptor. | |
session = requests.Session() | |
session.mount('https://', adapter) | |
# add the API keys to the session. | |
session.headers.update({ | |
'X-APIKeys': 'accessKey={}; secretKey={};'.format( | |
access_key, secret_key) | |
}) | |
# now make calls using session | |
session.get('https://cloud.tenable.com/scans') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment