From 8d933928d2d0f5b644d35bb808ed716454e8f206 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Mon, 23 Jul 2018 09:30:10 -0500 Subject: [PATCH] Only assume GET if no data, otherwise POST (#43133) * Only assume GET if no data, otherwise POST. Fixes #42876 #43091 #42750 --- changelogs/fragments/fix-open-url.yml | 2 ++ lib/ansible/module_utils/urls.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/fix-open-url.yml diff --git a/changelogs/fragments/fix-open-url.yml b/changelogs/fragments/fix-open-url.yml new file mode 100644 index 00000000000..c8c47e4001b --- /dev/null +++ b/changelogs/fragments/fix-open-url.yml @@ -0,0 +1,2 @@ +bugfixes: +- urls - Only assume GET method if data is empty, otherwise POST diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py index 6f6508500c6..25dc35504eb 100644 --- a/lib/ansible/module_utils/urls.py +++ b/lib/ansible/module_utils/urls.py @@ -1136,7 +1136,7 @@ def open_url(url, data=None, headers=None, method=None, use_proxy=True, Does not require the module environment ''' - method = method or 'GET' + method = method or ('POST' if data else 'GET') return Request().open(method, url, data=data, headers=headers, use_proxy=use_proxy, force=force, last_mod_time=last_mod_time, timeout=timeout, validate_certs=validate_certs, url_username=url_username, url_password=url_password, http_agent=http_agent,