pytest-testinfra icon indicating copy to clipboard operation
pytest-testinfra copied to clipboard

get_encoding: if python3 not found, failback

Open guillaumewatteeux opened this issue 3 years ago • 0 comments

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.

I add a try/except on backend/base.py to failback on locale.getpreferredencoding()

guillaumewatteeux avatar Jun 03 '22 13:06 guillaumewatteeux