Skip to content

httplib2 to requests migration #117

Closed
@sfultariya-crest

Description

@sfultariya-crest

Currently, splunktaucclib uses the httplib2 internally to make the API calls. In the next release of splunktaucclib (6.0.0), we will be replacing the httplib2 library with the requests library. This issue provides the change details.

Difference between httplib2 and requests:

  1. httplib2 returns (response_headers, content) and requests returns response
  2. In httplib2, the content is a type of bytes object which needs to be converted into an str object. In requests, we can directly get the str object using the response.text

Example:

Using httplib2:

import httplib2
h = httplib2.Http()
(response_headers, content) = h.request("http://example.org/", "GET")
print(response_headers.status)
data = content.decode('utf-8')

Using requests:

import requests
response = requests.request("GET", "http://example.org/")
print(response.status_code)
data = response.text

Code change require to use the splunktaucclib v6.0.0

Note: If you are using the splunktaucclib.alert_actions_base.ModularAlertBase class directly in your code then you need to make the below change in your source code to use the splunktaucclib v6.0.0.

  • The implementation of build_http_connection method (of class ModularAlertBase) is removed in the splunktaucclib v6.0.0. We recommend users to directly use the requests.request function to make the API calls. Doc: https://docs.python-requests.org/en/latest/api/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions