Skip to content

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

@oanatoly223

Description

@oanatoly223

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions