Bug report #18617
QGIS3: SagaUtils.py fails when comman contains non-latin characters
|Affected QGIS version:||3.1(master)||Regression?:||No|
|Operating System:||MacOS||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||26505|
On MacOS running a Saga command where paths or filenames include non-latin characters fails with
"SagaUtils.py", line 116, in createSagaBatchJobFileFromSagaCommands UnicodeEncodeError: 'ascii' codec can't encode characters in position 218-228: ordinal not in range(128)
The complete stack trace below:
File "/Applications/QGIS3.app/Contents/MacOS/../Resources/python/plugins/processing/algs/saga/SagaUtils.py", line 113, in createSagaBatchJobFileFromSagaCommands fout.write('saga_cmd ' + command.encode('utf8') + '\n') TypeError: must be str, not bytes During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Applications/QGIS3.app/Contents/MacOS/../Resources/python/plugins/processing/algs/saga/SagaAlgorithm.py", line 320, in processAlgorithm SagaUtils.createSagaBatchJobFileFromSagaCommands(commands) File "/Applications/QGIS3.app/Contents/MacOS/../Resources/python/plugins/processing/algs/saga/SagaUtils.py", line 116, in createSagaBatchJobFileFromSagaCommands fout.write('saga_cmd ' + command + '\n') UnicodeEncodeError: 'ascii' codec can't encode characters in position 218-228: ordinal not in range(128)
The failing code was introduced in
I do not have a Mac to test but I am afraid binary mode for the sagaBatchJobFilename and Grass7BatchJobFilename would be necessary
to port this correctly to Python 3.
[processing] fixed handling of input filenames with non-ascii characters
Looks like there is no problem now in SAGA when using filenames with non-ascii chars, so some code used for replacing filenames has been removed. Also some code for python2, which is not needed now.
#1 Updated by Jean Hemmi about 3 years ago
I have experienced the same issu on Windows with QGIS2 & this is alive with QGIS3.
I propose this bypass : call SAGA with temporary files (there is no non ascii there) and call a gdal transform with the right name (for instance temporary sdat is transfor in tiff).
Hope this'll help you