I have text with French accent in a DXF I import in QGIS3.16. The DXF is encoded in UTF-8 but as a result, the features attributes have encoding problems. The é charcacter are written é. Here's a portion of the code used:

# -*- coding: utf-8 -*-
layer = QgsVectorLayer(dxf_path + "|layername=entities|geometrytype=Point", "dxf_linestring", "ogr")

When I convert the DXF from UTF-8 to ANSI in Notepad++, the problem is solved but I would prefer to convert in the script rather than converting the whole file.

  • What about changing encoding in layer properties on the source tab?
    – Zoltan
    Dec 27, 2020 at 12:22

1 Answer 1


Maybe I didn't find a working method because the DXF dataprovider has not the capability.

Instead, I used a file encoding convert trick:

with open(file_utf8, 'rb') as source_file:
  with open(file_latin1, 'w+b') as dest_file:
    contents = source_file.read()

And it worked perfectly for my plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.