Hi, I run into this error but I can not fix it. Th...
# prefect-community
w
Hi, I run into this error but I can not fix it. The problem is: it run ok on my VSCode, but when I create a deployment and start an agent and run the code from prefect UI, it keep showing this error in Flows logs.
Copy code
UnicodeEncodeError: 'charmap' codec can't encode characters in position 13-14: character maps to <undefined>
I think it would be the same problem with this one: https://github.com/PrefectHQ/prefect/issues/5754 Thank you for your help!
Copy code
Encountered exception during execution:
Traceback (most recent call last):
  File "D:\python\lib\site-packages\prefect\engine.py", line 1445, in orchestrate_task_run
    result = await run_sync(task.fn, *args, **kwargs)
  File "D:\python\lib\site-packages\prefect\utilities\asyncutils.py", line 154, in run_sync_in_interruptible_worker_thread
    async with anyio.create_task_group() as tg:
  File "D:\python\lib\site-packages\anyio\_backends\_asyncio.py", line 662, in __aexit__
    raise exceptions[0]
  File "D:\python\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "D:\python\lib\site-packages\anyio\_backends\_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "D:\python\lib\site-packages\anyio\_backends\_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "D:\python\lib\site-packages\prefect\utilities\asyncutils.py", line 135, in capture_worker_thread_and_result
    result = __fn(*args, **kwargs)
  File "C:\Users\WILLTR~1\AppData\Local\Temp\tmpdl74duviprefect\prefect_test.py", line 106, in st1_extract_order_data
    print('Client: ' + shop_name)
  File "D:\python\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 13-14: character maps to <undefined>
r
When I've run into this with Python on Windows, setting the
PYTHONUTF8
environment variable to
1
usually solves it. This short writeup covers it pretty well.
w
So what exactly you did at that time? Here is what I tried, but it did not work • Run "set PYTHONUTF8=1" in CLI • Add "#!/usr/bin/env python" and "# coding: utf-8" to the beginning of script
r
I usually add it to the system variables as shown here: https://www.architectryan.com/2018/08/31/how-to-change-environment-variables-on-windows-10/
set PYTHONUTF8=1
should work, but only in the console you enter it in. The Windows agent starts flows in subprocesses, and each subprocess gets its own process group that doesn't share the parent process' console. So I think setting the env variable globally as either a user or system variable is the most reliable way to do it.
🙌 1
w
Hi @Ryan Peden. Thank you, I set PYTHONUTF8=1, and it is totally ok now.