MCPcopy Index your code
hub / github.com/python/cpython / urlopen

Function urlopen

Lib/urllib/request.py:137–187  ·  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" h

(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
            *, context=None)

Source from the content-addressed store, hash-verified

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

Callers 7

download_and_unpackFunction · 0.90
test_serverMethod · 0.90
purge.pyFile · 0.90
_test_urlsMethod · 0.85
test_ftp_errorMethod · 0.85
urlretrieveFunction · 0.85
_download_srcMethod · 0.85

Calls 3

HTTPSHandlerClass · 0.85
build_openerFunction · 0.85
openMethod · 0.45

Tested by 4

test_serverMethod · 0.72
_test_urlsMethod · 0.68
test_ftp_errorMethod · 0.68
_download_srcMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…