Skip to content

Commit

Permalink
Fix compatibility to fetch_url change in ansible-core devel (#30)
Browse files Browse the repository at this point in the history
* Fix compatibility to fetch_url change in ansible-core devel.

* Adjust #.
  • Loading branch information
felixfontein authored Nov 17, 2021
1 parent 3937f5b commit 94a76d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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

0 comments on commit 94a76d0

Please sign in to comment.