Skip to content

Instantly share code, notes, and snippets.

@markcam1
Created April 24, 2019 23:30
Show Gist options
  • Save markcam1/4de3908621943c3532aef3bce85b32f4 to your computer and use it in GitHub Desktop.
Save markcam1/4de3908621943c3532aef3bce85b32f4 to your computer and use it in GitHub Desktop.
Python: download website with basic auth and simple json parsing
import requests
import json
import logging
import getpass
#logging config:
logging.basicConfig(level=logging.DEBUG, format=' %(asctime)s - %(levelname)s - %(message)s')
logging.debug('Start of program')
# credentials
USER_NAME = '[email protected]'
print('Username: ' + USER_NAME)
try:
PASSWORD_ENTERED = getpass.getpass()
except Exception as error:
print('ERROR', error)
basicAuthCredentials = ( USER_NAME,PASSWORD_ENTERED )
# Send HTTP GET request to server and attempt to receive a response
try:
response = requests.get('https://jira.calypso.com/rest/api/2/project/CAL/versions', auth=basicAuthCredentials)
except requests.exceptions.RequestException as e:
print (e)
# If the HTTP GET request can be served
if response.status_code == 200:
rt = response.text
print('download complete')
parsedData = json.loads(rt)
#print(parsedData[0:4])
totalRows = 0
for i in parsedData:
totalRows += 1
#print(i["name"])
print(totalRows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment