Skip to content

Instantly share code, notes, and snippets.

@rameshkrishna
Created May 15, 2020 07:21
Show Gist options
  • Save rameshkrishna/206f4ed496f6c152ad95c45ff2021a37 to your computer and use it in GitHub Desktop.
Save rameshkrishna/206f4ed496f6c152ad95c45ff2021a37 to your computer and use it in GitHub Desktop.
Debgguing Python Requests
r = requests.get('https://api.github.com', auth=('user', 'pass'))
r is a response. It has a request attribute which has the information you need.
r.request.allow_redirects r.request.headers r.request.register_hook
r.request.auth r.request.hooks r.request.response
r.request.cert r.request.method r.request.send
r.request.config r.request.params r.request.sent
r.request.cookies r.request.path_url r.request.session
r.request.data r.request.prefetch r.request.timeout
r.request.deregister_hook r.request.proxies r.request.url
r.request.files r.request.redirect r.request.verify
r.request.headers gives the headers:
{'Accept': '*/*',
'Accept-Encoding': 'identity, deflate, compress, gzip',
'Authorization': u'Basic dXNlcjpwYXNz',
'User-Agent': 'python-requests/0.12.1'}
Then r.request.data has the body as a mapping. You can convert this with urllib.urlencode if they prefer:
https://stackoverflow.com/a/10588737
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment