Home / Function/ get_unicode_from_response() — requests Function Reference

get_unicode_from_response() — requests Function Reference

Architecture documentation for the get_unicode_from_response() function in utils.py from the requests codebase.

Entity Profile

Dependency Diagram

graph TD
  14580864_b859_b8af_2bd9_9a8f13e57a3d["get_unicode_from_response()"]
  2c39b9da_e317_5e6c_bbac_8362bac2110c["utils.py"]
  14580864_b859_b8af_2bd9_9a8f13e57a3d -->|defined in| 2c39b9da_e317_5e6c_bbac_8362bac2110c
  9ab5b77a_1e93_5426_2b6e_540e378c20b4["get_encoding_from_headers()"]
  14580864_b859_b8af_2bd9_9a8f13e57a3d -->|calls| 9ab5b77a_1e93_5426_2b6e_540e378c20b4
  style 14580864_b859_b8af_2bd9_9a8f13e57a3d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/requests/utils.py lines 579–615

def get_unicode_from_response(r):
    """Returns the requested content back in unicode.

    :param r: Response object to get unicode content from.

    Tried:

    1. charset from content-type
    2. fall back and replace all unicode characters

    :rtype: str
    """
    warnings.warn(
        (
            "In requests 3.0, get_unicode_from_response will be removed. For "
            "more information, please see the discussion on issue #2266. (This"
            " warning should only appear once.)"
        ),
        DeprecationWarning,
    )

    tried_encodings = []

    # Try charset from content-type
    encoding = get_encoding_from_headers(r.headers)

    if encoding:
        try:
            return str(r.content, encoding)
        except UnicodeError:
            tried_encodings.append(encoding)

    # Fall back:
    try:
        return str(r.content, encoding, errors="replace")
    except TypeError:
        return r.content

Domain

Subdomains

Frequently Asked Questions

What does get_unicode_from_response() do?
get_unicode_from_response() is a function in the requests codebase, defined in src/requests/utils.py.
Where is get_unicode_from_response() defined?
get_unicode_from_response() is defined in src/requests/utils.py at line 579.
What does get_unicode_from_response() call?
get_unicode_from_response() calls 1 function(s): get_encoding_from_headers.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free