Deprecated Requests Utilities

Requests has decided to deprecate some utility functions in requests.utils. To ease users’ lives, they’ve been moved to requests_toolbelt.utils.deprecated.

A collection of functions deprecated in requests.utils.

requests_toolbelt.utils.deprecated.find_charset()

Return a list of all non-overlapping matches of pattern in string.

requests_toolbelt.utils.deprecated.find_pragma()

Return a list of all non-overlapping matches of pattern in string.

requests_toolbelt.utils.deprecated.find_xml()

Return a list of all non-overlapping matches of pattern in string.

requests_toolbelt.utils.deprecated.get_encodings_from_content(content)

Return encodings from given content string.

import requests
from requests_toolbelt.utils import deprecated

r = requests.get(url)
encodings = deprecated.get_encodings_from_content(r)
Parameters:content (bytes) – bytestring to extract encodings from
Returns:encodings detected in the provided content
Return type:list(str)
requests_toolbelt.utils.deprecated.get_unicode_from_response(response)

Return the requested content back in unicode.

This will first attempt to retrieve the encoding from the response headers. If that fails, it will use requests_toolbelt.utils.deprecated.get_encodings_from_content() to determine encodings from HTML elements.

import requests
from requests_toolbelt.utils import deprecated

r = requests.get(url)
text = deprecated.get_unicode_from_response(r)
Parameters:response (requests.models.Response) – Response object to get unicode content from.