Cassette 存储和重放 HTTP 请求。
项目描述
Cassette 存储和重放 Python 应用程序中发出的 HTTP 请求。
import urllib2
import cassette
with cassette.play("data/responses.yaml"):
# If the request is not already stored in responses.yaml, cassette
# will request the URL and store its response in the file.
r = urllib2.urlopen("http://www.internic.net/domain/named.root")
# This time, the request response must be in the file. The external
# request is not made. cassette retrieves the response from the
# file.
r = urllib2.urlopen("http://www.internic.net/domain/named.root")
assert "A.ROOT-SERVERS.NET" in r.read(10000)
Cassette 还支持requests 库。
import requests
with cassette.play("data/responses.yaml"):
r = requests.get("http://www.internic.net/domain/named.root")
请注意,存储在不同库之间的请求可能彼此不兼容。也就是说,使用urllib2存储的请求可能仍会触发外部请求,因为使用requests 请求的 URL 相同。
安装
$ pip install cassette
文档
执照
盒式磁带在 MIT 许可证下可用。
版权所有 Uber 2013,Charles-Axel Dein < charles @ uber 。com >
项目详情
关
盒式磁带 -0.3.8.zip的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | fe09b7223ef14f93f1d58be51e959bf99df3422e7fb15aaa36fcd834b68bbade |
|
| MD5 | a75b59af3a023bb31998ad4947c75492 |
|
| 布莱克2-256 | afd9a05e70aac583b9bbe4c31e9af20f9c100b08a92b4b15b2fee7efeba8dbf7 |