-
Notifications
You must be signed in to change notification settings - Fork 4
/
authorize.py
50 lines (34 loc) · 1.67 KB
/
authorize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
"""authorize.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/159SabTCJokw2YlqyXiPJZdy7UfVE6HCa
Import the libraries so that they can be used within the notebook
* **requests** is used to make HTTP calls
* **json** is used to encode and decode strings into JSON
* **string** is used to perform text manipulation and checking
* **getpass** is used to do non-echoing password input
"""
import requests
import json
import string
import getpass
"""The **base_url** holds the URL to the SEEK instance that will be used in the notebook
**headers** holds the HTTP headers that will be sent with every HTTP call
* **Content-type: application/vnd.api+json** - indicates that any data sent will be in JSON API format
* **Accept: application/vnd.api+json** - indicates that the notebook expects any data returned to be in JSON API format
* **Accept-Charset: ISO-8859-1** - indicates that the notebook expects any text returned to be in ISO-8859-1 character set
"""
base_url = 'http://www.fairdomhub.org/'
headers = {"Content-type": "application/vnd.api+json",
"Accept": "application/vnd.api+json",
"Accept-Charset": "ISO-8859-1"}
"""Create a **requests** HTTP **Session**. A **Session** has re-usable settings such as **headers**
The **authorization** is username and password. The user is prompted for this information.
"""
session = requests.Session()
session.headers.update(headers)
session.auth = (input('Username:'), getpass.getpass('Password'))
"""Perform a test **GET** to ensure the username and password worked"""
r = session.get(base_url + 'models/311')
r.raise_for_status()