HTTP Library

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

  • urlstr URL for HTTP request
  • usernamestr Basic Auth username
  • passwordstr Basic Auth password
  • timeoutint timeout limit for request in milliseconds. Max is 60000
  • headersdict HTTP header
  • encodingstr 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
       

Make a POST request

HTTP.post(url, bodyusername=None, password=None, timeout=5000, headers=None, encoding='utf-8')

Performs HTTP POST request.

Credit cost: 1

Parameters

  • urlstr URL for HTTP request
  • bodystr body for HTTP request
  • usernamestr Basic Auth username (optional)
  • passwordstr Basic Auth password (optional)
  • timeoutint timeout limit for request in milliseconds. Max is 60000
  • headersdict HTTP header
  • encodingstr 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, bodyusername=None, password=None, timeout=5000, headers=None, encoding='utf-8')

Performs HTTP PUT request.

Credit cost: 1

Parameters

  • urlstr URL for HTTP request
  • bodystr body for HTTP request
  • usernamestr Basic Auth username
  • passwordstr Basic Auth password
  • timeoutint timeout limit for request in milliseconds. Max is 60000
  • headersdict HTTP header
  • encodingstr 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