Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility to fetch_url change in ansible-core devel #30

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/fetch_url-devel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "Generic module HTTP support code - fix usage of ``fetch_url`` with changes in latest ansible-core ``devel`` branch (https://github.com/ansible-collections/community.hrobot/pull/30)."
9 changes: 7 additions & 2 deletions plugins/module_utils/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
__metaclass__ = type


from ansible.module_utils.urls import fetch_url, open_url
from ansible.module_utils.six import PY3
from ansible.module_utils.six.moves.urllib.error import HTTPError
from ansible.module_utils.urls import fetch_url, open_url

import json
import time
Expand Down Expand Up @@ -89,8 +90,12 @@ def fetch_url_json(module, url, method='GET', timeout=10, data=None, headers=Non
module.params['force_basic_auth'] = True
resp, info = fetch_url(module, url, method=method, timeout=timeout, data=data, headers=headers)
try:
# In Python 2, reading from a closed response yields a TypeError.
# In Python 3, read() simply returns ''
if PY3 and resp.closed:
raise TypeError
content = resp.read()
except AttributeError:
except (AttributeError, TypeError):
content = info.pop('body', None)

if not content:
Expand Down