Skip to content

Instantly share code, notes, and snippets.

@tayler
Last active August 29, 2015 14:27
Show Gist options
  • Save tayler/4a438e3b94c26932f028 to your computer and use it in GitHub Desktop.
Save tayler/4a438e3b94c26932f028 to your computer and use it in GitHub Desktop.
import json, base64, pprint
import requests as r
requests.packages.urllib3.disable_warnings()
def make_request(username, password):
RI_API_USER = username
RI_API_PASSWORD = password
# Prep the authorization header
RI_ENCODED_AUTH = base64.b64encode(RI_API_USER + ":" + RI_API_PASSWORD)
RI_AUTH_HEADER = "Basic " + RI_ENCODED_AUTH
api_endpoint = "https://rightintel.com/api/v2/posts/search"
# Make the request
posts_resp = r.get(
"https://rightintel.com/api/v2/posts/search?limit=5",
headers={"Authorization": RI_AUTH_HEADER}
)
print "Connecting to the Right Intel API..."
if posts_resp.status_code == 403:
print "Access to the RI API was denied. Your API key and password may be incorrect."
elif posts_resp.status_code == 200:
print "API Call was successful"
print "Processing posts..."
print "Here are the posts:"
posts = json.loads(posts_resp.text)
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(posts)
else:
print "Error. This is the API call status code: ", posts_resp.status_code
exit()
if __name__ == "__main__":
usernameInput = ""
passwordInput = ""
while usernameInput != "exit":
usernameInput = input ("Enter your API username: ")
while passwordInput != "exit":
passwordInput = input ("Enter your API password: ")
make_request(usernameInput, passwordInput)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment