You are not logged in.
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
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
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
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
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
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