Skip to content

Instantly share code, notes, and snippets.

@SteveMcGrath
Created November 2, 2018 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SteveMcGrath/5aaf25d6a49afb316d90fb94ad192e0f to your computer and use it in GitHub Desktop.
Save SteveMcGrath/5aaf25d6a49afb316d90fb94ad192e0f to your computer and use it in GitHub Desktop.
Example connecting to Tenable.io w/o pyTenable or the Python SDK
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