2

When I ran the Doctests with Coverage in PyCharm, I got the following error:

Testing started at 12:25 AM ...
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2021.3.1\plugins\python\helpers\coverage_runner\run_coverage.py", line 34, in <module>
    a_file.write(os.getcwd()+"\n")
  File "C:\Users\kent8\anaconda3\envs\MyDjangoEnv\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 24-25: character maps to <undefined>

I'm using python 3.10.1 and UTF-8 in vs code. How to solve this?

Kent Chen
  • 21
  • 1
  • 1
  • 2
  • 4
    Does this answer your question? [UnicodeEncodeError: 'charmap' codec can't encode characters](https://stackoverflow.com/questions/27092833/unicodeencodeerror-charmap-codec-cant-encode-characters) – lamsal Feb 13 '22 at 06:45
  • 1
    You are clearly _not_ using UTF-8. The error happens because you are trying to write a Unicode string to a file opened for writing with the Windows `cp1252` encoding. This is a common error as such but without the actual code, we can't tell you what to fix. – tripleee Feb 13 '22 at 19:07

0 Answers0