Skip to content

开发者界面

¥Developer Interface

辅助函数

¥Helper Functions

笔记

¥Note

仅当您在控制台中测试 HTTPX 或发出少量请求时才使用这些函数。使用Client将启用 HTTP/2 和连接池,以实现更高效、更长寿命的连接。

¥Only use these functions if you're testing HTTPX in a console or making a small number of requests. Using a Client will enable HTTP/2 and connection pooling for more efficient and long-lived connections.

httpx.request(method, url, *, params=None, content=None, data=None, files=None, json=None, headers=None, cookies=None, auth=None, proxy=None, timeout=Timeout(timeout=5.0), follow_redirects=False, verify=True, trust_env=True)

发送 HTTP 请求。

¥Sends an HTTP request.

参数:

¥Parameters:

  • 方法- 新的 HTTP 方法Request目的:GETOPTIONSHEADPOSTPUTPATCH, 或者DELETE

    ¥method - HTTP method for the new Request object: GET, OPTIONS, HEAD, POST, PUT, PATCH, or DELETE.

  • 网址- 新的 URLRequest目的。

    ¥url - URL for the new Request object.

  • 参数-(选修的)查询要包含在 URL 中的参数,可以是字符串、字典或二元组序列。

    ¥params - (optional) Query parameters to include in the URL, as a string, dictionary, or sequence of two-tuples.

  • 内容-(选修的)包含在请求主体中的二进制内容,作为字节或字节迭代器。

    ¥content - (optional) Binary content to include in the body of the request, as bytes or a byte iterator.

  • 数据-(选修的)以字典形式包含在请求正文中的表单数据。

    ¥data - (optional) Form data to include in the body of the request, as a dictionary.

  • 文件-(选修的)包含在请求正文中的上传文件字典。

    ¥files - (optional) A dictionary of upload files to include in the body of the request.

  • json-(选修的)包含在请求正文中的 JSON 可序列化对象。

    ¥json - (optional) A JSON serializable object to include in the body of the request.

  • 标题-(选修的)包含在请求中的 HTTP 标头字典。

    ¥headers - (optional) Dictionary of HTTP headers to include in the request.

  • 曲奇饼-(选修的)请求中包含的 Cookie 项目字典。

    ¥cookies - (optional) Dictionary of Cookie items to include in the request.

  • 授权-(选修的)发送请求时使用的身份验证类。

    ¥auth - (optional) An authentication class to use when sending the request.

  • 代理人-(选修的)所有流量都应路由到的代理 URL。

    ¥proxy - (optional) A proxy URL where all the traffic should be routed.

  • 暂停-(选修的)发送请求时使用的超时配置。

    ¥timeout - (optional) The timeout configuration to use when sending the request.

  • follow_redirects-(选修的)启用或禁用 HTTP 重定向。

    ¥follow_redirects - (optional) Enables or disables HTTP redirects.

  • 核实-(选修的)任何一个True要使用带有默认 CA 包的 SSL 上下文,False禁用验证,或ssl.SSLContext使用自定义上下文。

    ¥verify - (optional) Either True to use an SSL context with the default CA bundle, False to disable verification, or an instance of ssl.SSLContext to use a custom context.

  • 信任环境-(选修的)启用或禁用环境变量的配置。

    ¥trust_env - (optional) Enables or disables usage of environment variables for configuration.

返回: Response

¥Returns: Response

用法:

¥Usage:

>>> import httpx
>>> response = httpx.request('GET', 'https://httpbin.org/get')
>>> response
<Response [200 OK]>
httpx.get(url, *, params=None, headers=None, cookies=None, auth=None, proxy=None, follow_redirects=False, verify=True, timeout=Timeout(timeout=5.0), trust_env=True)

发送GET要求。

¥Sends a GET request.

参数: 看httpx.request

¥Parameters: See httpx.request.

请注意datafilesjsoncontent此函数不提供参数,因为GET请求不应包含请求正文。

¥Note that the data, files, json and content parameters are not available on this function, as GET requests should not include a request body.

httpx.options(url, *, params=None, headers=None, cookies=None, auth=None, proxy=None, follow_redirects=False, verify=True, timeout=Timeout(timeout=5.0), trust_env=True)

发送OPTIONS要求。

¥Sends an OPTIONS request.

参数: 看httpx.request

¥Parameters: See httpx.request.

请注意datafilesjsoncontent此函数不提供参数,因为OPTIONS请求不应包含请求正文。

¥Note that the data, files, json and content parameters are not available on this function, as OPTIONS requests should not include a request body.

httpx.head(url, *, params=None, headers=None, cookies=None, auth=None, proxy=None, follow_redirects=False, verify=True, timeout=Timeout(timeout=5.0), trust_env=True)

发送HEAD要求。

¥Sends a HEAD request.

参数: 看httpx.request

¥Parameters: See httpx.request.

请注意datafilesjsoncontent此函数不提供参数,因为HEAD请求不应包含请求正文。

¥Note that the data, files, json and content parameters are not available on this function, as HEAD requests should not include a request body.

httpx.post(url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=None, proxy=None, follow_redirects=False, verify=True, timeout=Timeout(timeout=5.0), trust_env=True)

发送POST要求。

¥Sends a POST request.

参数: 看httpx.request

¥Parameters: See httpx.request.

httpx.put(url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=None, proxy=None, follow_redirects=False, verify=True, timeout=Timeout(timeout=5.0), trust_env=True)

发送PUT要求。

¥Sends a PUT request.

参数: 看httpx.request

¥Parameters: See httpx.request.

httpx.patch(url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=None, proxy=None, follow_redirects=False, verify=True, timeout=Timeout(timeout=5.0), trust_env=True)

发送PATCH要求。

¥Sends a PATCH request.

参数: 看httpx.request

¥Parameters: See httpx.request.

httpx.delete(url, *, params=None, headers=None, cookies=None, auth=None, proxy=None, follow_redirects=False, timeout=Timeout(timeout=5.0), verify=True, trust_env=True)

发送DELETE要求。

¥Sends a DELETE request.

参数: 看httpx.request

¥Parameters: See httpx.request.

请注意datafilesjsoncontent此函数不提供参数,因为DELETE请求不应包含请求正文。

¥Note that the data, files, json and content parameters are not available on this function, as DELETE requests should not include a request body.

httpx.stream(method, url, *, params=None, content=None, data=None, files=None, json=None, headers=None, cookies=None, auth=None, proxy=None, timeout=Timeout(timeout=5.0), follow_redirects=False, verify=True, trust_env=True)

替代httpx.request()它以流的方式传输响应主体,而不是立即将其加载到内存中。

¥Alternative to httpx.request() that streams the response body instead of loading it into memory at once.

参数: 看httpx.request

¥Parameters: See httpx.request.

参见:流式响应

¥See also: Streaming Responses

Client

¥Client

class httpx.Client(*, auth=None, params=None, headers=None, cookies=None, verify=True, cert=None, trust_env=True, http1=True, http2=False, proxy=None, mounts=None, timeout=Timeout(timeout=5.0), follow_redirects=False, limits=Limits(max_connections=100, max_keepalive_connections=20, keepalive_expiry=5.0), max_redirects=20, event_hooks=None, base_url='', transport=None, default_encoding='utf-8')

HTTP 客户端,具有连接池、HTTP/2、重定向、cookie 持久性等。

¥An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.

它可以在线程之间共享。

¥It can be shared between threads.

用法:

¥Usage:

>>> client = httpx.Client()
>>> response = client.get('https://example.org')

参数:

¥Parameters:

  • 授权-(选修的)发送请求时使用的身份验证类。

    ¥auth - (optional) An authentication class to use when sending requests.

  • 参数-(选修的)查询要包含在请求 URL 中的参数,可以是字符串、字典或二元组序列。

    ¥params - (optional) Query parameters to include in request URLs, as a string, dictionary, or sequence of two-tuples.

  • 标题-(选修的)发送请求时包含的 HTTP 标头字典。

    ¥headers - (optional) Dictionary of HTTP headers to include when sending requests.

  • 曲奇饼-(选修的)发送请求时包含的 Cookie 项目字典。

    ¥cookies - (optional) Dictionary of Cookie items to include when sending requests.

  • 核实-(选修的)任何一个True要使用带有默认 CA 包的 SSL 上下文,False禁用验证,或ssl.SSLContext使用自定义上下文。

    ¥verify - (optional) Either True to use an SSL context with the default CA bundle, False to disable verification, or an instance of ssl.SSLContext to use a custom context.

  • http2-(选修的)布尔值,指示是否应启用 HTTP/2 支持。默认为False

    ¥http2 - (optional) A boolean indicating if HTTP/2 support should be enabled. Defaults to False.

  • 代理人-(选修的)所有流量都应路由到的代理 URL。

    ¥proxy - (optional) A proxy URL where all the traffic should be routed.

  • 暂停-(选修的)发送请求时使用的超时配置。

    ¥timeout - (optional) The timeout configuration to use when sending requests.

  • 限制-(选修的)要使用的限制配置。

    ¥limits - (optional) The limits configuration to use.

  • 最大重定向次数-(选修的)应遵循的重定向响应的最大数量。

    ¥max_redirects - (optional) The maximum number of redirect responses that should be followed.

  • base_url-(选修的)构建请求 URL 时用作基础的 URL。

    ¥base_url - (optional) A URL to use as the base when building request URLs.

  • 运输-(选修的)用于通过网络发送请求的传输类。

    ¥transport - (optional) A transport class to use for sending requests over the network.

  • 信任环境-(选修的)启用或禁用环境变量的配置。

    ¥trust_env - (optional) Enables or disables usage of environment variables for configuration.

  • 默认编码-(选修的)如果响应的 Content-Type 标头中未包含字符集信息,则解码响应文本时使用的默认编码。设置为可调用函数以自动检测字符集。默认值:“utf-8”。

    ¥default_encoding - (optional) The default encoding to use for decoding response text, if no charset information is included in a response Content-Type header. Set to a callable for automatic character set detection. Default: "utf-8".

headers

发送请求时要包含的 HTTP 标头。

¥HTTP headers to include when sending requests.

cookies

发送请求时要包含的 Cookie 值。

¥Cookie values to include when sending requests.

params

发送请求时要包含在 URL 中的查询参数。

¥Query parameters to include in the URL when sending requests.

auth

当请求级别未传递任何内容时使用的身份验证类。

¥Authentication class used when none is passed at the request-level.

参见验证

¥See also Authentication.

request(self, method, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

建立并发送请求。

¥Build and send a request.

相当于:

¥Equivalent to:

request = client.build_request(...)
response = client.send(request, ...)

Client.build_request()Client.send()合并配置了解各种参数如何与客户端级配置合并。

¥See Client.build_request(), Client.send() and Merging of configuration for how the various parameters are merged with client-level configuration.

get(self, url, *, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

发送GET要求。

¥Send a GET request.

参数: 看httpx.request

¥Parameters: See httpx.request.

head(self, url, *, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

发送HEAD要求。

¥Send a HEAD request.

参数: 看httpx.request

¥Parameters: See httpx.request.

options(self, url, *, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

发送OPTIONS要求。

¥Send an OPTIONS request.

参数: 看httpx.request

¥Parameters: See httpx.request.

post(self, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

发送POST要求。

¥Send a POST request.

参数: 看httpx.request

¥Parameters: See httpx.request.

put(self, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

发送PUT要求。

¥Send a PUT request.

参数: 看httpx.request

¥Parameters: See httpx.request.

patch(self, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

发送PATCH要求。

¥Send a PATCH request.

参数: 看httpx.request

¥Parameters: See httpx.request.

delete(self, url, *, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

发送DELETE要求。

¥Send a DELETE request.

参数: 看httpx.request

¥Parameters: See httpx.request.

stream(self, method, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

替代httpx.request()它以流的方式传输响应主体,而不是立即将其加载到内存中。

¥Alternative to httpx.request() that streams the response body instead of loading it into memory at once.

参数: 看httpx.request

¥Parameters: See httpx.request.

参见:流式响应

¥See also: Streaming Responses

build_request(self, method, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, timeout=, extensions=None)

构建并返回请求实例。

¥Build and return a request instance.

  • paramsheaderscookies参数与客户端上设置的任何值合并。

    ¥The params, headers and cookies arguments are merged with any values set on the client.

  • url参数与任何合并base_url在客户端上设置。

    ¥The url argument is merged with any base_url set on the client.

参见:请求实例

¥See also: Request instances

send(self, request, *, stream=False, auth=, follow_redirects=)

发送请求。

¥Send a request.

请求按原样发送,未经修改。

¥The request is sent as-is, unmodified.

通常你会想要用Client.build_request()这样任何客户端级别的配置都会合并到请求中,但传递一个显式的httpx.Request()也受到支持。

¥Typically you'll want to build one with Client.build_request() so that any client-level configuration is merged into the request, but passing an explicit httpx.Request() is supported as well.

参见:请求实例

¥See also: Request instances

close(self)

关闭传输和代理。

¥Close transport and proxies.

AsyncClient

¥AsyncClient

class httpx.AsyncClient(*, auth=None, params=None, headers=None, cookies=None, verify=True, cert=None, http1=True, http2=False, proxy=None, mounts=None, timeout=Timeout(timeout=5.0), follow_redirects=False, limits=Limits(max_connections=100, max_keepalive_connections=20, keepalive_expiry=5.0), max_redirects=20, event_hooks=None, base_url='', transport=None, trust_env=True, default_encoding='utf-8')

异步 HTTP 客户端,具有连接池、HTTP/2、重定向、cookie 持久性等。

¥An asynchronous HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.

它可以在任务之间共享。

¥It can be shared between tasks.

用法:

¥Usage:

>>> async with httpx.AsyncClient() as client:
>>>     response = await client.get('https://example.org')

参数:

¥Parameters:

  • 授权-(选修的)发送请求时使用的身份验证类。

    ¥auth - (optional) An authentication class to use when sending requests.

  • 参数-(选修的)查询要包含在请求 URL 中的参数,可以是字符串、字典或二元组序列。

    ¥params - (optional) Query parameters to include in request URLs, as a string, dictionary, or sequence of two-tuples.

  • 标题-(选修的)发送请求时包含的 HTTP 标头字典。

    ¥headers - (optional) Dictionary of HTTP headers to include when sending requests.

  • 曲奇饼-(选修的)发送请求时包含的 Cookie 项目字典。

    ¥cookies - (optional) Dictionary of Cookie items to include when sending requests.

  • 核实-(选修的)任何一个True要使用带有默认 CA 包的 SSL 上下文,False禁用验证,或ssl.SSLContext使用自定义上下文。

    ¥verify - (optional) Either True to use an SSL context with the default CA bundle, False to disable verification, or an instance of ssl.SSLContext to use a custom context.

  • http2-(选修的)布尔值,指示是否应启用 HTTP/2 支持。默认为False

    ¥http2 - (optional) A boolean indicating if HTTP/2 support should be enabled. Defaults to False.

  • 代理人-(选修的)所有流量都应路由到的代理 URL。

    ¥proxy - (optional) A proxy URL where all the traffic should be routed.

  • 暂停-(选修的)发送请求时使用的超时配置。

    ¥timeout - (optional) The timeout configuration to use when sending requests.

  • 限制-(选修的)要使用的限制配置。

    ¥limits - (optional) The limits configuration to use.

  • 最大重定向次数-(选修的)应遵循的重定向响应的最大数量。

    ¥max_redirects - (optional) The maximum number of redirect responses that should be followed.

  • base_url-(选修的)构建请求 URL 时用作基础的 URL。

    ¥base_url - (optional) A URL to use as the base when building request URLs.

  • 运输-(选修的)用于通过网络发送请求的传输类。

    ¥transport - (optional) A transport class to use for sending requests over the network.

  • 信任环境-(选修的)启用或禁用环境变量的配置。

    ¥trust_env - (optional) Enables or disables usage of environment variables for configuration.

  • 默认编码-(选修的)如果响应的 Content-Type 标头中未包含字符集信息,则解码响应文本时使用的默认编码。设置为可调用函数以自动检测字符集。默认值:“utf-8”。

    ¥default_encoding - (optional) The default encoding to use for decoding response text, if no charset information is included in a response Content-Type header. Set to a callable for automatic character set detection. Default: "utf-8".

headers

发送请求时要包含的 HTTP 标头。

¥HTTP headers to include when sending requests.

cookies

发送请求时要包含的 Cookie 值。

¥Cookie values to include when sending requests.

params

发送请求时要包含在 URL 中的查询参数。

¥Query parameters to include in the URL when sending requests.

auth

当请求级别未传递任何内容时使用的身份验证类。

¥Authentication class used when none is passed at the request-level.

参见验证

¥See also Authentication.

async request(self, method, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

建立并发送请求。

¥Build and send a request.

相当于:

¥Equivalent to:

request = client.build_request(...)
response = await client.send(request, ...)

AsyncClient.build_request()AsyncClient.send()合并配置了解各种参数如何与客户端级配置合并。

¥See AsyncClient.build_request(), AsyncClient.send() and Merging of configuration for how the various parameters are merged with client-level configuration.

async get(self, url, *, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

发送GET要求。

¥Send a GET request.

参数: 看httpx.request

¥Parameters: See httpx.request.

async head(self, url, *, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

发送HEAD要求。

¥Send a HEAD request.

参数: 看httpx.request

¥Parameters: See httpx.request.

async options(self, url, *, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

发送OPTIONS要求。

¥Send an OPTIONS request.

参数: 看httpx.request

¥Parameters: See httpx.request.

async post(self, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

发送POST要求。

¥Send a POST request.

参数: 看httpx.request

¥Parameters: See httpx.request.

async put(self, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

发送PUT要求。

¥Send a PUT request.

参数: 看httpx.request

¥Parameters: See httpx.request.

async patch(self, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

发送PATCH要求。

¥Send a PATCH request.

参数: 看httpx.request

¥Parameters: See httpx.request.

async delete(self, url, *, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

发送DELETE要求。

¥Send a DELETE request.

参数: 看httpx.request

¥Parameters: See httpx.request.

stream(self, method, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, auth=, follow_redirects=, timeout=, extensions=None)

替代httpx.request()它以流的方式传输响应主体,而不是立即将其加载到内存中。

¥Alternative to httpx.request() that streams the response body instead of loading it into memory at once.

参数: 看httpx.request

¥Parameters: See httpx.request.

参见:流式响应

¥See also: Streaming Responses

build_request(self, method, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None, timeout=, extensions=None)

构建并返回请求实例。

¥Build and return a request instance.

  • paramsheaderscookies参数与客户端上设置的任何值合并。

    ¥The params, headers and cookies arguments are merged with any values set on the client.

  • url参数与任何合并base_url在客户端上设置。

    ¥The url argument is merged with any base_url set on the client.

参见:请求实例

¥See also: Request instances

async send(self, request, *, stream=False, auth=, follow_redirects=)

发送请求。

¥Send a request.

请求按原样发送,未经修改。

¥The request is sent as-is, unmodified.

通常你会想要用AsyncClient.build_request()这样任何客户端级别的配置都会合并到请求中,但传递一个显式的httpx.Request()也受到支持。

¥Typically you'll want to build one with AsyncClient.build_request() so that any client-level configuration is merged into the request, but passing an explicit httpx.Request() is supported as well.

参见:请求实例

¥See also: Request instances

async aclose(self)

关闭传输和代理。

¥Close transport and proxies.

Response

¥Response

HTTP 响应。

¥An HTTP response.

  • def __init__(...)

    ¥def __init__(...)

  • .status_code-整数

    ¥.status_code - int

  • .reason_phrase-字符串

    ¥.reason_phrase - str

  • .http_version-"HTTP/2"或者"HTTP/1.1"

    ¥.http_version - "HTTP/2" or "HTTP/1.1"

  • .url-网址

    ¥.url - URL

  • .headers-标题

    ¥.headers - Headers

  • .content-字节

    ¥.content - bytes

  • .text-字符串

    ¥.text - str

  • .encoding-字符串

    ¥.encoding - str

  • .is_redirect-布尔值

    ¥.is_redirect - bool

  • .request-要求

    ¥.request - Request

  • .next_request-可选[请求]

    ¥.next_request - Optional[Request]

  • .cookies-曲奇饼

    ¥.cookies - Cookies

  • .history-列表[响应]

    ¥.history - List[Response]

  • .elapsed-时间增量

    ¥.elapsed - timedelta

  • 发送请求和调用之间的时间间隔close()根据该请求收到的相应响应。总秒数()正确获取总经过的秒数。

    ¥The amount of time elapsed between sending the request and calling close() on the corresponding response received for that request. total_seconds() to correctly get the total elapsed seconds.

  • def .raise_for_status()-回复

    ¥def .raise_for_status() - Response

  • def .json()-任何

    ¥def .json() - Any

  • def .read()-字节

    ¥def .read() - bytes

  • def .iter_raw([chunk_size])-字节迭代器

    ¥def .iter_raw([chunk_size]) - bytes iterator

  • def .iter_bytes([chunk_size])-字节迭代器

    ¥def .iter_bytes([chunk_size]) - bytes iterator

  • def .iter_text([chunk_size])-文本迭代器

    ¥def .iter_text([chunk_size]) - text iterator

  • def .iter_lines()-文本迭代器

    ¥def .iter_lines() - text iterator

  • def .close()-没有任何

    ¥def .close() - None

  • def .next()-回复

    ¥def .next() - Response

  • def .aread()-字节

    ¥def .aread() - bytes

  • def .aiter_raw([chunk_size])-异步字节迭代器

    ¥def .aiter_raw([chunk_size]) - async bytes iterator

  • def .aiter_bytes([chunk_size])-异步字节迭代器

    ¥def .aiter_bytes([chunk_size]) - async bytes iterator

  • def .aiter_text([chunk_size])-异步文本迭代器

    ¥def .aiter_text([chunk_size]) - async text iterator

  • def .aiter_lines()-异步文本迭代器

    ¥def .aiter_lines() - async text iterator

  • def .aclose()-没有任何

    ¥def .aclose() - None

  • def .anext()-回复

    ¥def .anext() - Response

Request

¥Request

HTTP 请求。可以显式构造,以便更好地控制通过网络发送的具体内容。

¥An HTTP request. Can be constructed explicitly for more control over exactly what gets sent over the wire.

>>> request = httpx.Request("GET", "https://example.org", headers={'host': 'example.org'})
>>> response = client.send(request)
  • def __init__(method, url, [params], [headers], [cookies], [content], [data], [files], [json], [stream])

    ¥def __init__(method, url, [params], [headers], [cookies], [content], [data], [files], [json], [stream])

  • .method-字符串

    ¥.method - str

  • .url-网址

    ¥.url - URL

  • .content-字节字节迭代器, 或者字节异步迭代器

    ¥.content - byte, byte iterator, or byte async iterator

  • .headers-标题

    ¥.headers - Headers

  • .cookies-曲奇饼

    ¥.cookies - Cookies

URL

¥URL

规范化的、支持 IDNA 的 URL。

¥A normalized, IDNA supporting URL.

>>> url = URL("https://example.org/")
>>> url.host
'example.org'
  • def __init__(url, **kwargs)

    ¥def __init__(url, **kwargs)

  • .scheme-字符串

    ¥.scheme - str

  • .authority-字符串

    ¥.authority - str

  • .host-字符串

    ¥.host - str

  • .port-整数

    ¥.port - int

  • .path-字符串

    ¥.path - str

  • .query-字符串

    ¥.query - str

  • .raw_path-字符串

    ¥.raw_path - str

  • .fragment-字符串

    ¥.fragment - str

  • .is_ssl-布尔值

    ¥.is_ssl - bool

  • .is_absolute_url-布尔值

    ¥.is_absolute_url - bool

  • .is_relative_url-布尔值

    ¥.is_relative_url - bool

  • def .copy_with([scheme], [authority], [path], [query], [fragment])-网址

    ¥def .copy_with([scheme], [authority], [path], [query], [fragment]) - URL

Headers

¥Headers

不区分大小写的多字典。

¥A case-insensitive multi-dict.

>>> headers = Headers({'Content-Type': 'application/json'})
>>> headers['content-type']
'application/json'
  • def __init__(self, headers, encoding=None)

    ¥def __init__(self, headers, encoding=None)

  • def copy()-标题

    ¥def copy() - Headers

Cookies

¥Cookies

类似字典的 cookie 存储。

¥A dict-like cookie store.

>>> cookies = Cookies()
>>> cookies.set("name", "value", domain="example.org")
  • def __init__(cookies: [dict, Cookies, CookieJar])

    ¥def __init__(cookies: [dict, Cookies, CookieJar])

  • .jar-CookieJar

    ¥.jar - CookieJar

  • def extract_cookies(response)

    ¥def extract_cookies(response)

  • def set_cookie_header(request)

    ¥def set_cookie_header(request)

  • def set(name, value, [domain], [path])

    ¥def set(name, value, [domain], [path])

  • def get(name, [domain], [path])

    ¥def get(name, [domain], [path])

  • def delete(name, [domain], [path])

    ¥def delete(name, [domain], [path])

  • def clear([domain], [path])

    ¥def clear([domain], [path])

  • 标准可变映射接口

    ¥Standard mutable mapping interface

Proxy

¥Proxy

代理服务器的配置。

¥A configuration of the proxy server.

>>> proxy = Proxy("http://proxy.example.com:8030")
>>> client = Client(proxy=proxy)
  • def __init__(url, [ssl_context], [auth], [headers])

    ¥def __init__(url, [ssl_context], [auth], [headers])

  • .url-网址

    ¥.url - URL

  • .auth-元组[str,str]

    ¥.auth - tuple[str, str]

  • .headers-标题

    ¥.headers - Headers

  • .ssl_context-SSLContext

    ¥.ssl_context - SSLContext