This library provides the ability to perform HTTP get, push, and put.
Request Access
This library is not enabled by default. You will need to request access to this library from support@mediumone.com.
Import
To use this library and its functions, you must use the import line at the beginning of your Base Python code.
import HTTP
Make a GET request
HTTP.get(url, username=None, password=None, timeout=5000, headers=None, encoding='utf-8')
Performs HTTP GET request.
Credit cost: 1
Parameters
- url:
str
URL for HTTP request - username:
str
Basic Auth username - password:
str
Basic Auth password - timeout:
int
timeout limit for request in milliseconds. Max is 60000 - headers:
dict
HTTP header - encoding:
str
encoding for HTTP
Return Value
dict
of HTTP response
Example
-
Sample Code:
import HTTP
url = "https://somedomain.com/health"
header = {"Accept":"application/json","Content-Type":"application/json"}
response = HTTP.get(url, None, None, 30000, header, 'utf-8')
results = response["response"]
Exceptions
- HTTPException
- Invalid URL
- Exception
- Any connection related issue, such as timeout
- Any connection related issue, such as timeout
Make a POST request
HTTP.post(url, body, username=None, password=None, timeout=5000, headers=None, encoding='utf-8')
Performs HTTP POST request.
Credit cost: 1
Parameters
- url:
str
URL for HTTP request - body:
str
body for HTTP request - username:
str
Basic Auth username (optional) - password:
str
Basic Auth password (optional) - timeout:
int
timeout limit for request in milliseconds. Max is 60000 - headers:
dict
HTTP header - encoding:
str
encoding for HTTP
Return Value
dict
of HTTP response
Example
-
Sample Code:
import HTTP
import json
url = "https://somedomain.com/get_status"
body = {"key": ACCESS_KEY, "command": "status"}
header = {"Accept":"application/json","Content-Type":"application/json"}
response = HTTP.post(url, json.dumps(body), None, None, 30000, header, 'utf-8')
results = response["response"]
Exceptions
- HTTPException
- Invalid URL
- Exception
- Any connection related issue, such as timeout
Make a PUT request
HTTP.put(url, body, username=None, password=None, timeout=5000, headers=None, encoding='utf-8')
Performs HTTP PUT request.
Credit cost: 1
Parameters
- url:
str
URL for HTTP request - body:
str
body for HTTP request - username:
str
Basic Auth username - password:
str
Basic Auth password - timeout:
int
timeout limit for request in milliseconds. Max is 60000 - headers:
dict
HTTP header - encoding:
str
encoding for HTTP
Return Value
dict
of HTTP response
Example
-
Sample Code:
import HTTP
import json
url = "https://somedomain.com/get_status"
body = {"key": ACCESS_KEY, "command": "status"}
header = {"Accept":"application/json","Content-Type":"application/json"}
response = HTTP.put(url, json.dumps(body), None, None, 30000, header, 'utf-8')
results = response["response"]
Exceptions
- HTTPException
- Invalid URL
- Exception
- Any connection related issue, such as timeout