Catch new urllib3 exception: ProtocolError

The new version of requests (2.4.0) has updated underlying urllib3
to version 1.9. Unfortunately urllib3 introduced new exception
ProtocolError. Because of that unit tests in glance are failing:
ProtocolError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))

To solve this problem new urllib3 exception is caught in the same place
that the old one was. Unfortunately both exception are still in use so
I couldn't remove the old one.

Change-Id: I55eef98e734c59b9b627f182768a633b2b701e43
Closes-Bug: #1364893
This commit is contained in:
Pawel Koniszewski 2014-09-03 08:58:55 -04:00 committed by Zhi Yan Liu
parent 6dda6f306f
commit 16077d91dd
1 changed files with 5 additions and 1 deletions

View File

@ -18,6 +18,10 @@ import logging
import socket
import requests
try:
from requests.packages.urllib3.exceptions import ProtocolError
except ImportError:
ProtocolError = requests.exceptions.ConnectionError
import six
from six.moves.urllib import parse
@ -198,7 +202,7 @@ class HTTPClient(object):
message = ("Error communicating with %(endpoint)s %(e)s" %
dict(url=conn_url, e=e))
raise exc.InvalidEndpoint(message=message)
except requests.exceptions.ConnectionError as e:
except (requests.exceptions.ConnectionError, ProtocolError) as e:
message = ("Error finding address for %(url)s: %(e)s" %
dict(url=conn_url, e=e))
raise exc.CommunicationError(message=message)