Home / Function/ get_encodings_from_content() — requests Function Reference

get_encodings_from_content() — requests Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  3a884602_d763_405c_f036_d9ef28c96931["get_encodings_from_content()"]
  2c39b9da_e317_5e6c_bbac_8362bac2110c["utils.py"]
  3a884602_d763_405c_f036_d9ef28c96931 -->|defined in| 2c39b9da_e317_5e6c_bbac_8362bac2110c
  style 3a884602_d763_405c_f036_d9ef28c96931 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/requests/utils.py lines 477–499

def get_encodings_from_content(content):
    """Returns encodings from given content string.

    :param content: bytestring to extract encodings from.
    """
    warnings.warn(
        (
            "In requests 3.0, get_encodings_from_content will be removed. For "
            "more information, please see the discussion on issue #2266. (This"
            " warning should only appear once.)"
        ),
        DeprecationWarning,
    )

    charset_re = re.compile(r'<meta.*?charset=["\']*(.+?)["\'>]', flags=re.I)
    pragma_re = re.compile(r'<meta.*?content=["\']*;?charset=(.+?)["\'>]', flags=re.I)
    xml_re = re.compile(r'^<\?xml.*?encoding=["\']*(.+?)["\'>]')

    return (
        charset_re.findall(content)
        + pragma_re.findall(content)
        + xml_re.findall(content)
    )

Domain

Subdomains

Frequently Asked Questions

What does get_encodings_from_content() do?
get_encodings_from_content() is a function in the requests codebase, defined in src/requests/utils.py.
Where is get_encodings_from_content() defined?
get_encodings_from_content() is defined in src/requests/utils.py at line 477.

Analyze Your Own Codebase

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

Try Supermodel Free