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

get_encoding failed on windows system (with ansible backend) #654

Open
guillaumewatteeux opened this issue Jun 3, 2022 · 1 comment
Open

Comments

@guillaumewatteeux
Copy link

guillaumewatteeux commented Jun 3, 2022

see #653

When i wants to use ansible backend on windows host, i have a problem with ascii decode

Use ansible.windows.win_service_info to retrieve all services

def test_services(host):
    res = host.ansible(
        "ansible.windows.win_service_info", "", check=False
    )
    for service in res['services']:
        print(f"DEBUG {service['name']}")

result:

self = <encodings.ascii.IncrementalDecoder object at 0x7f695f40dfa0>
input = b'{"changed": false, "exists": true, "services": [{"checkpoint": 0, "controls_accepted": [], "dependencies": [], "depe...4d", "type": "network_endpoint"}], "username": "NT AUTHORITY\\\\SYSTEM", "wait_hint_ms": 0, "win32_exit_code": 1077}]}'
final = True

    def decode(self, input, final=False):
>       return codecs.ascii_decode(input, self.errors)[0]
E       UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 72968: ordinal not in range(128)

On windows, a service "Function Discovery Provider Host" contains a description with Web Services – Discovery (character 'En Dash', U+2013)
a 'En dash' character in service description ....

I'm using Ansible backend on windows, python don't install on it.

@guillaumewatteeux
Copy link
Author

Same issue with community.windows.win_certificate_info module. I have a certificate with Spanish characters in the information.

host.ansible("community.windows.win_certificate_info", ...)
self = <testinfra.backend.ansible.AnsibleBackend object at 0x7ff31cdfe650>
command = "python3 -c 'import locale;print(locale.getpreferredencoding())'"
args = ('python3',), kwargs = {'encoding': None}, host = None
out = {'changed': False, 'module_stderr': 'Exception calling "Create" with "1" argument(s): "At line:4 char:21\r\n+ def _ans...rrorId : BadExpression\r\n ', 'module_stdout': '', 'msg': 'MODULE FAILURE\nSee stdout/stderr for the exact error', ...}

I don't know howto force encoding to UTF-8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant