mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-09 22:36:14 +01:00
Merge branch 'improve_URLError_msg' of https://github.com/marcus-h/osc
Improve error message in case of an URLError.
This commit is contained in:
commit
26aea786da
@ -139,7 +139,11 @@ def run(prg, argv=None):
|
|||||||
except HTTPException as e:
|
except HTTPException as e:
|
||||||
print(e, file=sys.stderr)
|
print(e, file=sys.stderr)
|
||||||
except URLError as e:
|
except URLError as e:
|
||||||
print('Failed to reach a server:\n', e.reason, file=sys.stderr)
|
msg = 'Failed to reach a server'
|
||||||
|
if hasattr(e, '_osc_host_port'):
|
||||||
|
msg += ' (%s)' % e._osc_host_port
|
||||||
|
msg += ':\n'
|
||||||
|
print(msg, e.reason, file=sys.stderr)
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
# ignore broken pipe
|
# ignore broken pipe
|
||||||
if e.errno != errno.EPIPE:
|
if e.errno != errno.EPIPE:
|
||||||
|
@ -33,7 +33,7 @@ except ImportError:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from urllib.parse import urlsplit, urlunsplit, urlparse, quote_plus, urlencode, unquote
|
from urllib.parse import urlsplit, urlunsplit, urlparse, quote_plus, urlencode, unquote
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError, URLError
|
||||||
from urllib.request import pathname2url, install_opener, urlopen
|
from urllib.request import pathname2url, install_opener, urlopen
|
||||||
from urllib.request import Request as URLRequest
|
from urllib.request import Request as URLRequest
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
@ -42,7 +42,7 @@ except ImportError:
|
|||||||
#python 2.x
|
#python 2.x
|
||||||
from urlparse import urlsplit, urlunsplit, urlparse
|
from urlparse import urlsplit, urlunsplit, urlparse
|
||||||
from urllib import pathname2url, quote_plus, urlencode, unquote
|
from urllib import pathname2url, quote_plus, urlencode, unquote
|
||||||
from urllib2 import HTTPError, install_opener, urlopen
|
from urllib2 import HTTPError, URLError, install_opener, urlopen
|
||||||
from urllib2 import Request as URLRequest
|
from urllib2 import Request as URLRequest
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
from httplib import IncompleteRead
|
from httplib import IncompleteRead
|
||||||
@ -3402,6 +3402,9 @@ def http_request(method, url, headers={}, data=None, file=None):
|
|||||||
req.add_header('Content-Length', str(content_length))
|
req.add_header('Content-Length', str(content_length))
|
||||||
try:
|
try:
|
||||||
return urlopen(req)
|
return urlopen(req)
|
||||||
|
except URLError as e:
|
||||||
|
e._osc_host_port = req.host
|
||||||
|
raise
|
||||||
finally:
|
finally:
|
||||||
if hasattr(conf.cookiejar, 'save'):
|
if hasattr(conf.cookiejar, 'save'):
|
||||||
conf.cookiejar.save(ignore_discard=True)
|
conf.cookiejar.save(ignore_discard=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user