Solution: Get HTTP Status (Python 2.7 only)

Development | Programming languages
Description
Fetch url + Do the HTTP get request + Check for HTTP codes other than 200 + # Decode the JSON response into a dictionary and use the data
Attachments
No attachments.
Solutions
import requests

# Set the request parameters
url = 'https://www.google.com'

# Fetch url
print("Fetching url..")

# Do the HTTP get request
response = requests.get(url, verify=True) #Verify is check SSL certificate

# Error handling

# Check for HTTP codes other than 200
if response.status_code != 200:
   print('Status:', response.status_code, 'Problem with the request. Exiting.')
#exit()

# Decode the JSON response into a dictionary and use the data

data = response.json()

visitors = data[0]['dates'][0]['items'][0]['value']

print('Visitors today:'), visitors

on December 10th, 2018 (9:10 pm)
What masters said
You must sign in to comment!!
All comments
This solution has not been commented yet.
We use cookies to give you the best possible experience on our site. By continuing to use the site you agree to our use of cookies. Find out more Accept