HTTPError can also function as a non-exceptional file-like return value (#14915)

* HTTPError can also function as a non-exceptional file-like return value (the same thing that urlopen() returns)

* HTTPError - adding response to info dictionnary

* HTTPError - adding response to info dictionnary

* HTTPError - adding body response to info dictionnary
pull/15377/merge
Olivier GROSJEANNE 9 years ago committed by James Cammarata
parent f296d74329
commit 4647e8b74e

@ -897,7 +897,11 @@ def fetch_url(module, url, data=None, headers=None, method=None,
except (ConnectionError, ValueError), e: except (ConnectionError, ValueError), e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
except urllib2.HTTPError, e: except urllib2.HTTPError, e:
info.update(dict(msg=str(e), status=e.code, **e.info())) try:
body = e.read()
except AttributeError:
body = ''
info.update(dict(msg=str(e), status=e.code, body=body, **e.info()))
except urllib2.URLError, e: except urllib2.URLError, e:
code = int(getattr(e, 'code', -1)) code = int(getattr(e, 'code', -1))
info.update(dict(msg="Request failed: %s" % str(e), status=code)) info.update(dict(msg="Request failed: %s" % str(e), status=code))

Loading…
Cancel
Save