# Buggy code
def search_roles(self, search, **kwargs):
    search_url = self.baseurl + "/search/roles/?"

    if search:
        search_url += "&autocomplete=" + urlquote(search)

    tags = kwargs.get("tags", None)
    platforms = kwargs.get("platforms", None)
    page_size = kwargs.get("page_size", None)
    author = kwargs.get("author", None)

    if tags and isinstance(tags, string_types):
        tags = tags.split(",")
        search_url += "&tags_autocomplete=" + "+".join(tags)

    if platforms and isinstance(platforms, string_types):
        platforms = platforms.split(",")
        search_url += "&platforms_autocomplete=" + "+".join(platforms)

    if page_size:
        search_url += "&page_size=%s" % page_size

    if author:
        search_url += "&username_autocomplete=%s" % author

    data = self.__call_galaxy(search_url)
    return data


# Traceback (KeyError)
[notting@nostromo: ~]$ ansible-galaxy -vvv search "🐉🐉🐉"
ansible-galaxy 2.6.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/notting/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-galaxy
python version = 2.7.15 (default, May 16 2018, 17:50:09) [GCC 8.1.1 20180502 (Red Hat 8.1.1-1)]
Using /etc/ansible/ansible.cfg as config file
Opened /home/notting/.ansible_galaxy
ERROR! Unexpected Exception, this is probably a bug: u'\U0001f409'
the full traceback was:

Traceback (most recent call last):
File "/usr/bin/ansible-galaxy", line 118, in <module>
exit_code = cli.run()
File "/usr/lib/python2.7/site-packages/ansible/cli/galaxy.py", line 152, in run
self.execute()
File "/usr/lib/python2.7/site-packages/ansible/cli/__init__.py", line 155, in execute
fn()
File "/usr/lib/python2.7/site-packages/ansible/cli/galaxy.py", line 521, in execute_search
tags=self.options.galaxy_tags, author=self.options.author, page_size=page_size)
File "/usr/lib/python2.7/site-packages/ansible/galaxy/api.py", line 56, in wrapped
return method(self, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/ansible/galaxy/api.py", line 249, in search_roles
search_url += '&amp;autocomplete=' + urlquote(search)
File "/usr/lib64/python2.7/urllib.py", line 1298, in quote
return ''.join(map(quoter, s))
KeyError: u'\U0001f409'

# Fixed code
def search_roles(self, search, **kwargs):
    search_url = self.baseurl + "/search/roles/?"

    if search:
        search_url += "&autocomplete=" + to_text(urlquote(to_bytes(search)))

    tags = kwargs.get("tags", None)
    platforms = kwargs.get("platforms", None)
    page_size = kwargs.get("page_size", None)
    author = kwargs.get("author", None)

    if tags and isinstance(tags, string_types):
        tags = tags.split(",")
        search_url += "&tags_autocomplete=" + "+".join(tags)

    if platforms and isinstance(platforms, string_types):
        platforms = platforms.split(",")
        search_url += "&platforms_autocomplete=" + "+".join(platforms)

    if page_size:
        search_url += "&page_size=%s" % page_size

    if author:
        search_url += "&username_autocomplete=%s" % author

    data = self.__call_galaxy(search_url)
    return data