UnicodeEncodeError: 'charmap' codec can't encode character '\ufeff' in position 3: character maps to <undefined>
See original GitHub issueHi all 👋
I’m getting this error while running the script and updating the sources. I’m on Windows 10 with Python 3.8.3.
Traceback (most recent call last):
File "updateHostsFile.py", line 1750, in <module>
main()
File "updateHostsFile.py", line 282, in main
final_file = remove_dups_and_excl(merge_file, exclusion_regexes)
File "updateHostsFile.py", line 937, in remove_dups_and_excl
hostname, normalized_rule = normalize_rule(
File "updateHostsFile.py", line 1025, in normalize_rule
print("==>%s<==" % rule)
File "C:\Python38\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\ufeff' in position 3: character maps to <undefined>
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
UnicodeEncodeError: 'charmap' codec can't encode ...
The reason why it is working is because the encoding is changed to UTF-8 when using the file, so characters in UTF-8 are...
Read more >UnicodeEncodeError: 'charmap' codec can't encode ...
UnicodeEncodeError : 'charmap' codec can't encode character u'\u2026' in position 139: character maps to <undefined> #1. Open. baditaflorin opened this issue on ...
Read more >'charmap' codec can't encode characters in position 0-14 ...
Hi! How to solve "UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-14: character maps to " for this code: stockList ...
Read more >'charmap' codec can't encode characters in position
The Python "UnicodeEncodeError: 'charmap' codec can't encode characters in position" occurs when we use an incorrect codec to encode a string to ...
Read more >"UnicodeEncodeError: 'charmap' codec can't encode ...
INTERNALERROR occurs running pytest - "UnicodeEncodeError: 'charmap' codec can't encode characters in position ...: character maps to <undefined>".
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Assuming that we are talking about the
cp1252
encoding as mentioned in:I can’t (literally) reproduce.
Therefore, I don’t know where the problem is here. Unless OP can give us more information, I’m not going to look for a problem which may not exist.
Other info
Python version
Why using the
PYTHONIOENCODING
environment variable?As the problem comes from
print()
, that means that I can reproduce by changing the defaultstdout
encoding.Here is the example, which proves that it’s working.
Now what about
\ufeff
?I never played with it but it is here good explained.
So I tried, with
PYTHONIOENCODING
(again).With
CP1252
With
UTF-8
Now, talking about this project (itself), I really don’t know where
\ufeff
comes from as the line:is generated at the end… And I really can’t find anything about this.
@StevenBlack @XhmikosR I leave the rest for you!
What’s your system config and the exact command you are using to run the script? Also, I assume you are on the latest
master
?