易于使用的HTTP客户端
项目描述
urlfetch是Python的一个简单、轻量级且易于使用的HTTP客户端。它作为单个文件模块分发,除了Python标准库外没有其他依赖。
亮点
作为单个文件模块分发,除了Python标准库外没有其他依赖。
纯Python,与gevent兼容。
小代码库,约1000行,其中30%是注释和空白行。只需10分钟即可了解所有细节。
随机用户代理。
支持流式传输。
安装
$ pip install urlfetch
hello, world
import urlfetch
response = urlfetch.get('https://pythonlang.cn/')
print response.status, response.reason
print len(response.content)
上传文件
import urlfetch
response = urlfetch.post(
'http://127.0.0.1:8888/upload',
headers = {
'Referer': 'http://127.0.0.1/',
},
files = {
'fieldname1': open('/path/to/file', 'rb'),
#'fieldname2': 'file content', # file must have a filename
'fieldname3': ('filename', open('/path/to/file2', 'rb')),
'fieldname4': ('filename', 'file content'),
},
data = {
'foo': 'bar'
},
)
print response.status, response.content
测试
要运行测试,urlfetch依赖于bottle和gunicorn。如果通过调用python setup.py test运行测试,将自动处理依赖关系(通过tests_require)。因此,如果您想直接运行测试,即python tests/testall.py,请确保bottle和gunicorn已安装在PYTHONPATH下。
项目详情
关闭
urlfetch-2.0.1.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | bc1e60a71b2c6177b25830dda39daf2a230b6ce11c7bf2186098a785523adaa5 |
|
MD5 | fa7c5b06245c6e2eca7eb215c58f49a9 |
|
BLAKE2b-256 | bba1e1d6b044af47c9ccda8b04b8b03c78faec238f7fadac3526f2ce86205033 |