diff --git a/changelogs/fragments/uri_httpexception.yml b/changelogs/fragments/uri_httpexception.yml new file mode 100644 index 00000000000..d2b339cf3b8 --- /dev/null +++ b/changelogs/fragments/uri_httpexception.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - uri - Handle HTTP exceptions raised while reading the content (https://github.com/ansible/ansible/issues/83794). diff --git a/lib/ansible/modules/uri.py b/lib/ansible/modules/uri.py index ab390bc2b93..5ca88127de2 100644 --- a/lib/ansible/modules/uri.py +++ b/lib/ansible/modules/uri.py @@ -732,6 +732,8 @@ def main(): # there was no content, but the error read() # may have been stored in the info as 'body' content = info.pop('body', b'') + except http.client.HTTPException as http_err: + module.fail_json(msg=f"HTTP Error while fetching {url}: {to_native(http_err)}") elif r: content = r else: