How to use 'urllib3 urlopen' in Python

Every line of 'urllib3 urlopen' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
125def urlopen(self, method, url, redirect=True, **kw):
126 """
127 Same as :meth:`urllib3.connectionpool.HTTPConnectionPool.urlopen`
128 with custom cross-host redirect logic and only sends the request-uri
129 portion of the ``url``.
130
131 The given ``url`` parameter must be absolute, such that an appropriate
132 :class:`urllib3.connectionpool.ConnectionPool` can be chosen for it.
133 """
134 u = parse_url(url)
135 conn = self.connection_from_host(u.host, port=u.port, scheme=u.scheme)
136
137 kw['assert_same_host'] = False
138 kw['redirect'] = False
139 if 'headers' not in kw:
140 kw['headers'] = self.headers
141
142 response = conn.urlopen(method, u.request_uri, **kw)
143
144 redirect_location = redirect and response.get_redirect_location()
145 if not redirect_location:
146 return response
147
148 if response.status == 303:
149 method = 'GET'
150
151 log.info("Redirecting %s -> %s" % (url, redirect_location))
152 kw['retries'] = kw.get('retries', 3) - 1 # Persist retries countdown
153 kw['redirect'] = redirect
154 return self.urlopen(method, redirect_location, **kw)
84def urlopen(self, method, url, body=None, headers=None, retries=3, redirect=True, assert_same_host=True):
85 if headers is None:
86 headers = {}
87 headers['Connection'] = 'Keep-Alive'
88 return super(NTLMConnectionPool, self).urlopen(method, url, body, headers, retries, redirect, assert_same_host)

Related snippets