You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2022-05-30 17:19:41

oreshkin
Member
Registered: 2022-05-30
Posts: 3

unable add location (utf-8 russian leters) using python-glpi-api.

Hello,

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 ?

Offline

#2 2022-05-30 20:51:08

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,819
Website

Re: unable add location (utf-8 russian leters) using python-glpi-api.

Where did you find this API library? I don't see it in the official GLPI Project GitHub.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#3 2022-05-31 14:56:15

oreshkin
Member
Registered: 2022-05-30
Posts: 3

Re: unable add location (utf-8 russian leters) using python-glpi-api.

I've found it at github.com/truly-systems/glpi-sdk-python and from github.com/giggsoff/glpi-sdk-python/tree/master/glpi,
which is a fork of first API library.

Both API library claim that:

This SDK is written in Python to help developers integrate their apps, APIS and scripts in GLPI infrastructure. This SDK abstract the GLPI Rest   
API github.com/glpi-project/glpi/blob/9.1/bugfixes/apirest.md


Where is API library for python from official GLPI Project GitHub ?

Do you think that API library from  official GLPI Project GitHub does not have such problem ?

Offline

#4 2022-05-31 15:10:13

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,819
Website

Re: unable add location (utf-8 russian leters) using python-glpi-api.

There is no official API library for Python. This seems like something that needs fixed in the unofficial library itself although I cannot even find where the error is being generated.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#5 2022-06-06 15:39:54

oreshkin
Member
Registered: 2022-05-30
Posts: 3

Re: unable add location (utf-8 russian leters) using python-glpi-api.

I've resolved my problem in such a way:

object_data = {"name": object_name.encode('utf-8').decode('latin-1')}

But I have a question regarding encodings used in GLPI.

Does it mean that GLPI accept only 'latin-1'   encoding ?

Or  GLPI may accept any encoding including 'utf-8'  ?   If it is the case then   how do I specify an ecoding for GLPI ?

Offline

#6 2022-06-06 16:41:06

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,819
Website

Re: unable add location (utf-8 russian leters) using python-glpi-api.

I don't see how this is an issue with GLPI. The encoding error is coming from the python scripts before any data is sent to GLPI.
There is no reason why GLPI wouldn't be able to accept UTF characters through the API.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

Board footer

Powered by FluxBB