Python Encoding
BMPCreated with Sketch.BMPZIPCreated with Sketch.ZIPXLSCreated with Sketch.XLSTXTCreated with Sketch.TXTPPTCreated with Sketch.PPTPNGCreated with Sketch.PNGPDFCreated with Sketch.PDFJPGCreated with Sketch.JPGGIFCreated with Sketch.GIFDOCCreated with Sketch.DOC Error Created with Sketch.
question

Python Encoding

Par
DiegoG
Créé le 2020-06-26 14:53:19 (edited on 2024-09-04 12:28:36) dans Serveurs Privés Virtuels (VPS)

Bonjour, j'ai transféré mon code sur mon vps. J'ai un problème d'encodage comme ci dessous :
> Traceback (most recent call last):
> File "test.py", line 5, in
> print(data)
> UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 11: ordinal not in range(128)

Voici mon code rien de plus simple :
> # -*- coding: utf-8 -*-
> import json
> with open("Data Traitement/runes_list.json", 'r', encoding="utf8") as file:
> data = json.load(file)
> print(data)

Bien évidement ce code est fonctionnel en local sur mon ordinateur. Avez vous une solution ou suis-je le seul avec ce problème ? (Ce n'est pas pour faire une site web)

Merci de vos réponses.


1 réponse ( Latest reply on 2020-06-27 22:03:35 Par
Christophe T
)

Ton shell n'est pas en utf8 sans doute. (la commande "locale" affiche l'encodage du shell)

Il faudrait voir si c'est python3 qui est utilisé et pas python2.