MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / urlopen

Function urlopen

tools/python-3.11.9-amd64/Lib/urllib/request.py:139–216  ·  view source on GitHub ↗

Open the URL url, which can be either a string or a Request object. *data* must be an object specifying additional data to be sent to the server, or None if no such data is needed. See Request for details. urllib.request module uses HTTP/1.1 and includes a "Connection:close"

(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
            *, cafile=None, capath=None, cadefault=False, context=None)

Source from the content-addressed store, hash-verified

137
138_opener = None
139def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
140 *, cafile=None, capath=None, cadefault=False, context=None):
141 '''Open the URL url, which can be either a string or a Request object.
142
143 *data* must be an object specifying additional data to be sent to
144 the server, or None if no such data is needed. See Request for
145 details.
146
147 urllib.request module uses HTTP/1.1 and includes a "Connection:close"
148 header in its HTTP requests.
149
150 The optional *timeout* parameter specifies a timeout in seconds for
151 blocking operations like the connection attempt (if not specified, the
152 global default timeout setting will be used). This only works for HTTP,
153 HTTPS and FTP connections.
154
155 If *context* is specified, it must be a ssl.SSLContext instance describing
156 the various SSL options. See HTTPSConnection for more details.
157
158 The optional *cafile* and *capath* parameters specify a set of trusted CA
159 certificates for HTTPS requests. cafile should point to a single file
160 containing a bundle of CA certificates, whereas capath should point to a
161 directory of hashed certificate files. More information can be found in
162 ssl.SSLContext.load_verify_locations().
163
164 The *cadefault* parameter is ignored.
165
166
167 This function always returns an object which can work as a
168 context manager and has the properties url, headers, and status.
169 See urllib.response.addinfourl for more detail on these properties.
170
171 For HTTP and HTTPS URLs, this function returns a http.client.HTTPResponse
172 object slightly modified. In addition to the three new methods above, the
173 msg attribute contains the same information as the reason attribute ---
174 the reason phrase returned by the server --- instead of the response
175 headers as it is specified in the documentation for HTTPResponse.
176
177 For FTP, file, and data URLs and requests explicitly handled by legacy
178 URLopener and FancyURLopener classes, this function returns a
179 urllib.response.addinfourl object.
180
181 Note that None may be returned if no handler handles the request (though
182 the default installed global OpenerDirector uses UnknownHandler to ensure
183 this never happens).
184
185 In addition, if proxy settings are detected (for example, when a *_proxy
186 environment variable like http_proxy is set), ProxyHandler is default
187 installed and makes sure the requests are handled through the proxy.
188
189 '''
190 global _opener
191 if cafile or capath or cadefault:
192 import warnings
193 warnings.warn("cafile, capath and cadefault are deprecated, use a "
194 "custom context instead.", DeprecationWarning, 2)
195 if context is not None:
196 raise ValueError(

Callers 8

upload_fileMethod · 0.90
upload_fileMethod · 0.90
_download_classifiersFunction · 0.90
generateFunction · 0.90
verify_wheelFunction · 0.90
get_jsonFunction · 0.90
urlretrieveFunction · 0.85
_get_external_dataFunction · 0.85

Calls 5

build_openerFunction · 0.85
HTTPSHandlerClass · 0.70
warnMethod · 0.45
set_alpn_protocolsMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected