파이썬 - UnicodeEncodeError: 'ascii' codec can't encode character '...' in position ...: ordinal not in range(128)
이렇게 UnicodeEncodeError 오류가 발생한다면?
# pip show fastapi
Name: fastapi
Version: 0.83.0
Summary: FastAPI framework, high performance, easy to learn, fast to code, ready for production
Home-page: https://github.com/tiangolo/fastapi
--- Logging error ---
Traceback (most recent call last):
File "/usr/local/lib/python3.6/logging/__init__.py", line 996, in emit
stream.write(msg)
UnicodeEncodeError: 'ascii' codec can't encode character '\xe1' in position 15: ordinal not in range(128)
Call stack:
File "/usr/local/bin/pip", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/site-packages/pip/_internal/cli/main.py", line 70, in main
return command.main(cmd_args)
File "/usr/local/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 98, in main
return self._main(args)
File "/usr/local/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 212, in _main
return run(options, args)
File "/usr/local/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 164, in exc_logging_wrapper
status = run_func(*args)
File "/usr/local/lib/python3.6/site-packages/pip/_internal/commands/show.py", line 48, in run
results, list_files=options.files, verbose=options.verbose
File "/usr/local/lib/python3.6/site-packages/pip/_internal/commands/show.py", line 212, in print_results
write_output("Author: %s", dist.author)
File "/usr/local/lib/python3.6/site-packages/pip/_internal/utils/misc.py", line 390, in write_output
logger.info(msg, *args)
Message: 'Author: %s'
Arguments: ('Sebasti\xe1n Ram\xedrez',)
Author-email: tiangolo@gmail.com
License:
Location: /usr/local/lib/python3.6/site-packages
Requires: pydantic, starlette
Required-by:
보는 바와 같이 "'Sebasti\xe1n Ram\xedrez'" 텍스트에 유니코드가 사용된 것이므로,
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128)
; https://stackoverflow.com/questions/9942594/unicodeencodeerror-ascii-codec-cant-encode-character-u-xa0-in-position-20
간단하게 PYTHONIOENCODING 환경변수만 설정해 주면 정상적으로 동작합니다.
# export PYTHONIOENCODING=utf8
# pip show fastapi
Name: fastapi
Version: 0.83.0
Summary: FastAPI framework, high performance, easy to learn, fast to code, ready for production
Home-page: https://github.com/tiangolo/fastapi
Author: Sebastián Ramírez
Author-email: tiangolo@gmail.com
License:
Location: /usr/local/lib/python3.6/site-packages
Requires: pydantic, starlette
Required-by:
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]