` 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如何用新列表替换ListView的列表   swing Java JFrame布局   java JNativehook未捕获密码   java JPA仅获取一级关联   java KeyListener是否停止使用动作或鼠标Listener?   shell如何在Ubuntu中安装java   java如何通过使用会话检索数据来跳过空值。冬眠   java如何在jsp中获取列表   java Android仅在位置(0,0)上缩放,而不是在整个图像上缩放   Java for循环格式化控制台   协议缓冲区Protobuf Java不区分大小写映射?   java模拟对象,并将它们分配给方法中的实例和静态变量   java是否可以在执行时看到对对象的所有引用?   wcf Java客户端和InstanceContextMode   java我在XMLGregorianCalendar中的“20170526T04:08:00.000+05:30”中有一个日期,我需要将其转换为20170526T04:08:00.000z   java如何让两个小程序共享字段   java保留CSS注释而不修改YUI压缩器中的内容   java Android(Kotlin)具有非字符串基元类型的双向数据绑定   Java swing:warning组合框是原始类型。对泛型类型JComboBox<E>的引用应参数化