Server IP : 85.214.239.14 / Your IP : 3.129.23.11 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /usr/lib/python3/dist-packages/httpcore/ |
Upload File : |
from contextlib import contextmanager from typing import Iterator, Optional, Union from ._models import URL, Extensions, HeaderTypes, Response from ._sync.connection_pool import ConnectionPool def request( method: Union[bytes, str], url: Union[URL, bytes, str], *, headers: HeaderTypes = None, content: Union[bytes, Iterator[bytes], None] = None, extensions: Optional[Extensions] = None, ) -> Response: """ Sends an HTTP request, returning the response. ``` response = httpcore.request("GET", "https://www.example.com/") ``` Arguments: method: The HTTP method for the request. Typically one of `"GET"`, `"OPTIONS"`, `"HEAD"`, `"POST"`, `"PUT"`, `"PATCH"`, or `"DELETE"`. url: The URL of the HTTP request. Either as an instance of `httpcore.URL`, or as str/bytes. headers: The HTTP request headers. Either as a dictionary of str/bytes, or as a list of two-tuples of str/bytes. content: The content of the request body. Either as bytes, or as a bytes iterator. extensions: A dictionary of optional extra information included on the request. Possible keys include `"timeout"`. Returns: An instance of `httpcore.Response`. """ with ConnectionPool() as pool: return pool.request( method=method, url=url, headers=headers, content=content, extensions=extensions, ) @contextmanager def stream( method: Union[bytes, str], url: Union[URL, bytes, str], *, headers: HeaderTypes = None, content: Union[bytes, Iterator[bytes], None] = None, extensions: Optional[Extensions] = None, ) -> Iterator[Response]: """ Sends an HTTP request, returning the response within a content manager. ``` with httpcore.stream("GET", "https://www.example.com/") as response: ... ``` When using the `stream()` function, the body of the response will not be automatically read. If you want to access the response body you should either use `content = response.read()`, or `for chunk in response.iter_content()`. Arguments: method: The HTTP method for the request. Typically one of `"GET"`, `"OPTIONS"`, `"HEAD"`, `"POST"`, `"PUT"`, `"PATCH"`, or `"DELETE"`. url: The URL of the HTTP request. Either as an instance of `httpcore.URL`, or as str/bytes. headers: The HTTP request headers. Either as a dictionary of str/bytes, or as a list of two-tuples of str/bytes. content: The content of the request body. Either as bytes, or as a bytes iterator. extensions: A dictionary of optional extra information included on the request. Possible keys include `"timeout"`. Returns: An instance of `httpcore.Response`. """ with ConnectionPool() as pool: with pool.stream( method=method, url=url, headers=headers, content=content, extensions=extensions, ) as response: yield response