def urlopen(self, method, path, **kwargs):
"""
Make a request using the next server according to the connection
strategy, and retries up to max_retries attempts. Ultimately,
if the request still failed, we reraise the HTTPError from
urllib3. If at the start of the request, there are no known
available hosts, we revive all dead connections and forcefully
attempt to reconnect.
"""
# If we're trying to initiate a new connection, and
# all connections are already dead, then we should flail
# and attempt to connect to one of them
if len(self.connections) == 0:
self.force_revive()
# We don't need strict host checking since our client is enforcing
# the correct behavior anyways
kwargs.setdefault('assert_same_host', False)
try:
for _ in xrange(self.max_retries):
conn = self.strategy.next(self.connections)
try:
return conn.urlopen(method, path, **kwargs)
except HTTPError:
self.mark_dead(conn)
if len(self.connections) == 0:
raise
finally:
self.cleanup_dead()
评论列表
文章目录