跳转到主要内容

一个针对Requests的简单HTTP客户端。

项目描述

为Requests 3.0提供的实验性底层异步HTTP客户端


目标:将urllib3代码库,添加异步支持(具有多个后端),对于阻塞调用,默认使用trio执行异步函数。

用法

异步用法

import requests_core

url = "http://httpbin.org/uuid"

async def main():
    r = await requests_core.request('GET', url)
    print(r.headers)
    print(await r.read())
>>> import trio
>>> trio.run(main)
    HTTPHeaderDict({'connection': 'keep-alive', 'server': 'meinheld/0.6.1', 'date': 'Fri, 16 Mar 2018 11:59:57 GMT', 'content-type': 'application/json', 'access-control-allow-origin': '*', 'access-control-allow-credentials': 'true', 'x-powered-by': 'Flask', 'x-processed-time': '0', 'content-length': '53', 'via': '1.1 vegur'})
    b'{\n  "uuid": "693947c9-9f49-4b4a-be94-73a152ce1acb"\n}\n'

同步用法

>>> r = requests_core.blocking_request('GET', URL)
>>> print()
<requests_core.http_manager._async.response.HTTPResponse object at 0x103f63c88>

安装

这是一个正在进行中的工作。不要安装它。

由以下支持