truly-systems/glpi-sdk-python

unable create location with name in utf-8 (russian letters)

oanatoly223 opened this issue · 1 comments

I am trying to add to my GLPI new location using python-glpi-api.

Name of location in utf-8 (russian letters)

Here is my code:

where

    object_type = "location"
    object_name = "Биржевая"   #   name of location in utf-8 (russian letters)

    result = []
    self.logger.info("object_name= {}   type= {}".format(object_name, type(object_name)))
    object_data = {"name": object_name}
    self.logger.info("object_data= {}   object_name type {}".format(object_data, type(object_name)))
    try:
        glpi_object = json.dumps(self.glpi.create(object_type, object_data),
                         ensure_ascii=False,
                         indent=4,
                         separators=(',', ': '),
                         sort_keys=False
        )

        result = glpi_object
    except Exception as err:
        self.logger.error("create_glpi_object: Caught exception  {}".format(err))
        return False, str(err)
    return True, result         

I've got the following error message:

May 26 13:57:06 outss-1 GLPIRunner:[14990]: INFO object_name= Биржевая type= <class 'str'>
May 26 13:57:06 outss-1 GLPIRunner:[14990]: INFO object_data= {'name': 'Биржевая'} object_name type <class 'str'>
May 26 13:57:06 outss-1 GLPIRunner:[14990]: ERROR create_glpi_object: Caught exception 'latin-1' codec can't encode characters in position
22-29: Body ('Биржевая') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.

If I set location name in latin like this

object_name = "Birzhevaya"

then location is added to GLPI sucessfuly.

Using recommendation body.encode('utf-8') does not work.

What can I do to work around this problem ?

Any hints ?

I've solved this problem in a such way:
object_data = {"name": object_name.encode('utf-8').decode('latin-1')}

But does it mean that GLPI accept only 'latin-1' ?
Or may be GLPI permit utf-8 too, but glpi-sdk-python package accept only 'latin-1' ?