Currently all our scripts are python2-based, not sure if running them with Python3 would need a major change, but currently we're happy with Python2. I'm still not clear if this is a bug or an additional option should be supplied in order to make this work.

Thanks.

El 2017-06-12 14:48, Fabrice Bacchella escribió:
Did you try with python 3 ? UTF management changed a lot with this
version, it might works better in your case.

Le 12 juin 2017 à 12:33, nico...@devels.es a écrit :

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.
_______________________________________________
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users
_______________________________________________
Users mailing list
Users@ovirt.org
http://lists.ovirt.org/mailman/listinfo/users

Reply via email to