text() — requests Function Reference
Architecture documentation for the text() function in models.py from the requests codebase.
Entity Profile
Dependency Diagram
graph TD 682e5576_9766_d5c5_82ae_492cf5a9ca16["text()"] eb32847e_3797_d01a_6e44_345e9ea7e251["Response"] 682e5576_9766_d5c5_82ae_492cf5a9ca16 -->|defined in| eb32847e_3797_d01a_6e44_345e9ea7e251 style 682e5576_9766_d5c5_82ae_492cf5a9ca16 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/requests/models.py lines 912–947
def text(self):
"""Content of the response, in unicode.
If Response.encoding is None, encoding will be guessed using
``charset_normalizer`` or ``chardet``.
The encoding of the response content is determined based solely on HTTP
headers, following RFC 2616 to the letter. If you can take advantage of
non-HTTP knowledge to make a better guess at the encoding, you should
set ``r.encoding`` appropriately before accessing this property.
"""
# Try charset from content-type
content = None
encoding = self.encoding
if not self.content:
return ""
# Fallback to auto-detected encoding.
if self.encoding is None:
encoding = self.apparent_encoding
# Decode unicode from given encoding.
try:
content = str(self.content, encoding, errors="replace")
except (LookupError, TypeError):
# A LookupError is raised if the encoding was not found which could
# indicate a misspelling or similar mistake.
#
# A TypeError can be raised if encoding is None
#
# So we try blindly encoding.
content = str(self.content, errors="replace")
return content
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does text() do?
text() is a function in the requests codebase, defined in src/requests/models.py.
Where is text() defined?
text() is defined in src/requests/models.py at line 912.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free