[ovirt-users] Python-SDK4: Managing accents?
nicolas at devels.es
nicolas at devels.es
Mon Jun 12 10:33:37 UTC 2017
Hi,
We're running Python SDK (ovirt-engine-sdk-python) ver 4.1.4 and we're
having some issues getting values that contain accents. For example,
this snippet fails:
import ovirtsdk4 as sdk
import ovirtsdk4.types as types
# Create the connection to the server:
connection = sdk.Connection(
url='https://fqdn/ovirt-engine/api',
username='...',
password='...',
ca_file='...',
debug=True,
)
users_service = connection.system_service().users_service()
users = users_service.list()
connection.close()
This snippet fails in the "users = users_service.list()" line, because
one of the records have a tilde (ó).
The trace is:
Traceback (most recent call last):
File "lista_users", line 23, in <module>
users = users_service.list()
File
"/home/ovirt/prueba/ejemplo2/lib/python2.7/site-packages/ovirtsdk4/services.py",
line 22155, in list
return self._internal_get(headers, query, wait)
File
"/home/ovirt/prueba/ejemplo2/lib/python2.7/site-packages/ovirtsdk4/service.py",
line 202, in _internal_get
return future.wait() if wait else future
File
"/home/ovirt/prueba/ejemplo2/lib/python2.7/site-packages/ovirtsdk4/service.py",
line 53, in wait
return self._code(response)
File
"/home/ovirt/prueba/ejemplo2/lib/python2.7/site-packages/ovirtsdk4/service.py",
line 197, in callback
return self._internal_read_body(response)
File
"/home/ovirt/prueba/ejemplo2/lib/python2.7/site-packages/ovirtsdk4/service.py",
line 310, in _internal_read_body
return reader.Reader.read(response.body)
File
"/home/ovirt/prueba/ejemplo2/lib/python2.7/site-packages/ovirtsdk4/reader.py",
line 297, in read
cursor = xml.XmlReader(io.BytesIO(source.encode('utf-8')))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
1899: ordinal not in range(128)
Opening the source code (ovirtsdk4/reader.py) file and seeking the exact
line that fails I can see:
if isinstance(source, str):
cursor = xml.XmlReader(io.BytesIO(source.encode('utf-8')))
If I add a line just after the 'if' being "cursor =
cursor.decode('utf-8')", it seems to work, but I guess the source code
should handle this kind of situations.
Is this a known issue? Should I open a BZ? Any workaround meanwhile?
Thanks.
More information about the Users
mailing list