From 4647e8b74e614e5ed82becd0eb502d79d10d2b13 Mon Sep 17 00:00:00 2001 From: Olivier GROSJEANNE Date: Mon, 25 Apr 2016 19:21:45 +0200 Subject: [PATCH] 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 --- lib/ansible/module_utils/urls.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py index 0c00fe87be9..26185672864 100644 --- a/lib/ansible/module_utils/urls.py +++ b/lib/ansible/module_utils/urls.py @@ -897,7 +897,11 @@ def fetch_url(module, url, data=None, headers=None, method=None, except (ConnectionError, ValueError), e: module.fail_json(msg=str(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: code = int(getattr(e, 'code', -1)) info.update(dict(msg="Request failed: %s" % str(e), status=code))