Created
November 7, 2022 10:05
-
-
Save Bowser1704/e64762627e990a5d5ecb2e4345efcead to your computer and use it in GitHub Desktop.
dump requests http request and response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dump(res, *args, **kw): | |
"""dump HTTP request and response""" | |
# request spec | |
method = res.request.method | |
url = res.url | |
print(f"> {method} {url}") | |
# request headers | |
for k, v in res.request.headers.items(): | |
print(f"> {k}: {v}") | |
# reqeuest body | |
body = res.request.body | |
if body: | |
print(body) | |
print() | |
# response code | |
print(f"< {res.status_code}") | |
# response headers | |
for k, v in res.headers.items(): | |
print(f"> {k}: {v}") | |
# response body | |
print(res.text) | |
print("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment