…
httpcore的Python项目详细描述
httpcore
功能支持
http/2
和http/1.1
支持。异步
/等待
支持非阻塞http请求。- 默认情况下,任何地方都有严格的超时。
- 完全键入注释。
- 100%测试覆盖率。
加上请求的所有标准功能…
- 国际域名和网址
- 保持活动连接池
- 具有cookie持久性的会话
- 浏览器样式的SSL验证
- 基本/摘要式身份验证
- 优雅的钥匙/价值饼干
- 自动解压缩
- 自动内容解码
- Unicode响应正文
- 多部分文件上载todo-请求内容当前支持url编码的数据、json、字节或异步字节迭代器。
- http(s)代理支持
- 连接超时
- 流媒体下载
- .netrc支持todo
- 分块请求
用法
提出请求:
>>>importhttpcore>>>client=httpcore.Client()>>>response=client.get('https://example.com')>>>response.status_code<HTTPStatus.OK:200>>>>response.protocol'HTTP/2'>>>response.text'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>\n...'
或者,异步请求:
注意:使用ipython
从控制台尝试,因为它支持等待
>>>importhttpcore>>>client=httpcore.AsyncClient()>>>response=awaitclient.get('https://example.com')>>>response.status_code<StatusCode.OK:200>>>>response.protocol'HTTP/2'>>>response.text'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>\n...'
依赖关系
h2
-http/2支持。h11
-http/1.1支持。证书
-ssl证书。chardet
-回退自动检测响应编码。idna
-国际化域名支持。rfc3986
-url解析和规范化。brotlipy
-解码"brotli"压缩响应。(可选)
大量的信用是由于api布局的请求
接下来的大部分工作,以及
urllib3
的大量设计
从低级网络细节中获得灵感。
API参考
客户机
一个http客户端,具有连接池、重定向、cookie持久性等功能。
>>>client=Client()>>>response=client.get('https://example.org')
def初始([auth]、[cookies]、[verify]、[cert]、[timeout]、[pool\u limits]、[max\u redirects]、[dispatch])
def.request(方法,url,[数据],[参数],[头],[cookies],[验证],[流],[允许重定向],[验证],[证书],[超时])
def.get(url,[params],[headers],[cookies],[auth],[stream],[allow_redirects],[verify],[cert],[timeout])
定义选项(url,[params],[headers],[cookies],[auth],[stream],[allow_redirects],[verify],[cert],[timeout])
def.head(url,[params],[headers],[cookies],[auth],[stream],[allow_redirects],[verify],[cert],[timeout])
def.post(url,[数据],[json],[参数],[标题],[cookies],[验证],[流],[允许重定向],[验证],[证书],[超时])
def.put(url,[数据],[json],[参数],[标题],[cookies],[验证],[流],[允许指导,[验证],[证书],[超时]
def.patch(url,[数据],[json],[参数],[标题],[cookies],[验证],[流],[允许重定向],[验证],[证书],[超时])
def.delete(url,[数据],[json],[参数],[标题],[cookies],[验证],[流],[允许重定向],[验证],[证书],[超时])
def.send(请求,[流],[允许重定向],[验证],[证书],[超时])
def.close()
响应
一个http响应。
定义初始化(…)
。状态代码
-int(通常是astatuscode
intenum.)。原因短语
-str。协议
-"http/2"
或"http/1.1"
.url
-url。标题
-标题。内容
-字节.text
-str。编码
-str。是否重定向
-bool。请求
-请求.cookies
-cookies。历史记录
-列表[响应]def.raise_for_status()
-无def.json()
-任何def.read()
-字节def.stream()
-字节迭代器def.raw()
-字节迭代器def.close()
-无def.next()
-响应
请求
一个http请求。可以显式地构造,以便更精确地控制 通过电线发送的内容。
>>>request=Request("GET","https://example.org",headers={'host':'example.org'})>>>response=client.send(request)
def初始(方法,url,[params],[data],[json],[headers],[cookies])
。方法
-str.url
-url.content
-字节或字节异步迭代器。标题
-标题.cookies
-cookies
url
一个标准化的、支持idna的url。
>>>url=URL("https://example.org/")>>>url.host'example.org'
def\uu init(url,allow\u relative=false,params=none)
.scheme
-str。权限
-str.host
-str.port
-int.path
-str。查询
-str。完整路径
-str。片段
-str。是ssl
-bool。原点
-原点。是绝对的url
-bool。是相对的URL
-booldef.copy_with([方案],[权限],[路径],[查询],[片段])
-urldef.resolve_with(url)
-url
原点
一组规范的、支持IDNA的方案/主机/端口信息。
>>>Origin('https://example.org')==Origin('HTTPS://EXAMPLE.ORG:443')True
def初始(url)
。是ssl
-bool.host
-str.port
-int
标题
不区分大小写的多指令。
>>>headers=Headers({'Content-Type':'application/json'})>>>headers['content-type']'application/json'
def\uu init(self,headers)
cookies
像dict一样的饼干店。
>>>cookies=Cookies()>>>cookies.set("name","value",domain="example.org")
def初始化(cookies:[dict,cookies,cookiejar])
.jar
-Cookiejardef extract_cookies(响应)
def set_cookie_header(请求)
def set(名称、值、[域]、[路径])
def get(名称,[域],[路径])
def delete(名称,[域],[路径])
def clear([域],[路径])
- 标准可变映射接口
备用后端
异步客户端
异步客户端。
trioclient
待办事项
堆栈中有两个主要层。客户端处理重定向,
cookie持久性(todo)和身份验证(todo)。调度员
处理发送实际请求和获取响应。堆栈
客户端
-重定向、身份验证、cookies等。连接池(Dispatcher)
-连接池保持活动。
httpconnection
-单个连接。
http 1 1连接
-单个http/1.1连接。http 2连接
-单个http/2连接,具有多个流。推荐PyPI第三方库