跳转到主要内容

易于使用的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依赖于bottlegunicorn。如果通过调用python setup.py test运行测试,将自动处理依赖关系(通过tests_require)。因此,如果您想直接运行测试,即python tests/testall.py,请确保bottle和gunicorn已安装在PYTHONPATH下。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

urlfetch-2.0.1.tar.gz (67.1 kB 查看哈希值)

上传时间

支持