mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-06 06:04:24 -07:00
uri: Avoid false traceback in common scenarios (#39526)
* uri: Avoid exception in common scenario So I was confused by the fact that the **uri** module, when not returning an acceptable HTTP status code, returns: The full traceback is: File "/tmp/ansible_UQwiI4/ansible_module_uri.py", line 471, in main uresp['location'] = absolute_location(url, uresp['location']) While the actual error was: Status code was 400 and not [201]: HTTP Error 400: I also wonder why that message ends abruptly. I would have expected `HTTP Error 400: Bad Request` which would be more useful. * uri: Avoid false positive tracebacks in fail_json() on PY2
This commit is contained in:
parent
6eacfecb73
commit
32b5992578
1 changed files with 5 additions and 5 deletions
|
@ -261,12 +261,13 @@ import datetime
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from collections import Mapping, Sequence
|
from collections import Mapping, Sequence
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.six import iteritems, string_types
|
from ansible.module_utils.six import PY2, iteritems, string_types
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlencode, urlsplit
|
from ansible.module_utils.six.moves.urllib.parse import urlencode, urlsplit
|
||||||
from ansible.module_utils._text import to_native, to_text
|
from ansible.module_utils._text import to_native, to_text
|
||||||
from ansible.module_utils.urls import fetch_url, url_argument_spec
|
from ansible.module_utils.urls import fetch_url, url_argument_spec
|
||||||
|
@ -564,10 +565,8 @@ def main():
|
||||||
ukey = key.replace("-", "_").lower()
|
ukey = key.replace("-", "_").lower()
|
||||||
uresp[ukey] = value
|
uresp[ukey] = value
|
||||||
|
|
||||||
try:
|
if 'location' in uresp:
|
||||||
uresp['location'] = absolute_location(url, uresp['location'])
|
uresp['location'] = absolute_location(url, uresp['location'])
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Default content_encoding to try
|
# Default content_encoding to try
|
||||||
content_encoding = 'utf-8'
|
content_encoding = 'utf-8'
|
||||||
|
@ -581,7 +580,8 @@ def main():
|
||||||
js = json.loads(u_content)
|
js = json.loads(u_content)
|
||||||
uresp['json'] = js
|
uresp['json'] = js
|
||||||
except:
|
except:
|
||||||
pass
|
if PY2:
|
||||||
|
sys.exc_clear() # Avoid false positive traceback in fail_json() on Python 2
|
||||||
else:
|
else:
|
||||||
u_content = to_text(content, encoding=content_encoding)
|
u_content = to_text(content, encoding=content_encoding)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue