` requests dump`为请求提供钩子函数。
requests-dump的Python项目详细描述
提供一个钩子函数来转储请求的http通信。
请,请,请注意,这个库处于alpha前阶段,并且 其接口可能会发生更改。
用法
您可以将钩子函数传递给请求的方法函数。
>>> import requests >>> import reqdump >>> requests.get('http://example.com/', hooks=dict(response=reqdump.dump)) > GET http://example.com/ > Accept-Encoding: gzip, deflate, compress > Accept: */* > User-Agent: python-requests/2.2.1 CPython/2.7.6 Darwin/13.0.2 < 200 OK < content-length: 1270 < x-ec-custom-error: 1 < x-cache: HIT < accept-ranges: bytes < expires: Tue, 11 Feb 2014 13:41:46 GMT < server: ECS (sjc/4FB4) < last-modified: Fri, 09 Aug 2013 23:54:35 GMT < etag: "359670651" < cache-control: max-age=604800 < date: Tue, 04 Feb 2014 13:41:46 GMT < content-type: text/html <!doctype html> <html> (... snip ...) <Response [200]> >>>
您还可以对所有请求的方法函数应用补丁来使用钩子 功能。
>>> import requests >>> import reqdump >>> reqdump.patch() >>> requests.get('http://example.com/') > GET http://example.com/ > Accept-Encoding: gzip, deflate, compress (... snip ...) <Response [200]> >>> reqdump.unpatch() # discard patches >>> requests.get('http://example.com/') <Response [200]> >>>
历史记录
0.1.3
- 将patch()重命名为patch all(),将unpatch()重命名为unpatch all()
- 支持get以外的http方法
0.1.2
- 添加patch()和unpatch()函数
0.1.1
- 支持Python3.3
0.1
- 出生!