diff --git a/changelogs/fragments/42866-galaxy-search-unicode.yaml b/changelogs/fragments/42866-galaxy-search-unicode.yaml new file mode 100644 index 0000000000..0ae472a073 --- /dev/null +++ b/changelogs/fragments/42866-galaxy-search-unicode.yaml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-galaxy - Prevent unicode errors when searching - https://github.com/ansible/ansible/issues/42866 diff --git a/lib/ansible/galaxy/api.py b/lib/ansible/galaxy/api.py index 15251b61b3..78c8d1c736 100644 --- a/lib/ansible/galaxy/api.py +++ b/lib/ansible/galaxy/api.py @@ -30,7 +30,7 @@ from ansible.galaxy.token import GalaxyToken from ansible.module_utils.six import string_types from ansible.module_utils.six.moves.urllib.error import HTTPError from ansible.module_utils.six.moves.urllib.parse import quote as urlquote, urlencode -from ansible.module_utils._text import to_native, to_text +from ansible.module_utils._text import to_bytes, to_native, to_text from ansible.module_utils.urls import open_url try: @@ -178,7 +178,7 @@ class GalaxyAPI(object): """ Find a role by name. """ - role_name = urlquote(role_name) + role_name = to_text(urlquote(to_bytes(role_name))) try: parts = role_name.split(".") @@ -246,7 +246,7 @@ class GalaxyAPI(object): search_url = self.baseurl + '/search/roles/?' if search: - search_url += '&autocomplete=' + urlquote(search) + search_url += '&autocomplete=' + to_text(urlquote(to_bytes(search))) tags = kwargs.get('tags', None) platforms = kwargs.get('platforms', None)