` 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

  • 出生!

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何下载多个。java中的PDF文件   linux Java打开文件,形成实际用户主页~/   java如何在时间线内维护TableView选择?   java Hibernate注释@Where vs@WhereJoinTable   Java读/写访问异常FileNotFoundException(访问被拒绝)   继承在Java中是否可以扩展最后一个类?   Android HttpClient使用java使应用程序崩溃。lang.OutOfMemoryError:pthread_create   java为什么即使我在proguardproject中添加了jar文件,也会出现这种错误。txt?   如果添加JButton,swing Java FocusListener和KeyListener将无法工作   java使用solrj检索json格式的SolrDocument   使用Microsoft Visual Studio代码进行Java编程   java NoClassDefFoundError:org/apache/log4j/Logger   哈希集中包含相等对象的java   java中的参数化构造函数是否需要有一个主体?   java类似于NetBeans不必要的代码检测器   Java实践问题   java Blackberry“[projectname].调试文件丢失”和“I/O错误:找不到程序”jar