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
This commit is contained in:
parent
f296d74329
commit
4647e8b74e
1 changed files with 5 additions and 1 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Reference in a new issue