Hi!
I am currently trying to run a Batch Processing for the Urban Flood Risk Mitigation Model. I can run the model from the GUI but when i save it as a python script and try to run it it gives me this error:
SyntaxError: (unicode error) ‘utf-8’ codec can’t decode byte 0xfc in position 38: invalid start byte
Do you maybe know what the problem is and how to fix it?
Thanks for posting. This can when there is a non ascii character and it can’t be encoded / decoded properly. But InVEST should be handling this.
Within your python script you should see a line like this: logging.basicConfig(level=logging.INFO, handlers=[handler])
Could you edit the logging level to debug, so it looks like this: logging.basicConfig(level=logging.DEBUG, handlers=[handler])
Could you then capture the output from the model run and upload it as a text file or paste it here?
One way to do that from the command line would be to: python my_script.py > urban_log.txt
Hi @Doug,
thanks for the answer. I tried to change the logging to debug, but it still gives me the same error as before. I don’t think the model creates any output. Here is the complete log of the model run:
Traceback (most recent call last):
File “C:\Program Files\Python38\lib\runpy.py”, line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File “C:\Program Files\Python38\lib\runpy.py”, line 86, in run_code
exec(code, run_globals)
File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy_main.py", line 45, in
cli.main()
File “c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy/…\debugpy\server\cli.py”, line 444, in main
run()
File “c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy/…\debugpy\server\cli.py”, line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str(“main”))
File “C:\Program Files\Python38\lib\runpy.py”, line 262, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File “C:\Program Files\Python38\lib\runpy.py”, line 237, in _get_code_from_file
code = compile(f.read(), fname, ‘exec’)
Der Thread 0x1 hat mit Code 0 (0x0) geendet.
File “C:\Users\felix\OneDrive\Documents\Uni\Masterarbeit\inVEST\Flood Risk Migitation\Python\Flood Risk Batch Processing\Flood_Risk_Batch_Processing.py”, line 24
‘aoi_watersheds_path’: 'C:/Users/felix/OneDrive/Documents/Uni/Masterarbeit/inVEST/Flood ’
^
SyntaxError: (unicode error) ‘utf-8’ codec can’t decode byte 0xfc in position 38: invalid start byte
Thanks for posting that, it’s helpful. Could you attach your python script file or paste it here? It actually looks like the issue is happening even before an InVEST model is being run.
This might be because of the formatting here in the topic, but I’m noticing two types of single-quotation marks in your source code:
straight quotation marks (')
curly quotation marks (‘)
Although python source code does support many types of unicode characters, I don’t believe that curly quotation marks are a supported means of identifying strings. If you change them all to straight quotation marks (either ' or "), I wonder if that will correct this issue.
If that doesn’t resolve the issue, could you either attach the file itself or else share the textfile directly with us somehow? I think the forums software’s rendering here might be getting in the way of identifying what’s wrong.
Hi,
sorry for not replying. I could solve the problem in the mean time, i just had to set the default encoding of visual studio to utf8. Thanks for the help anyways!
Best Regards
Felix