peterbe/mincss

UnicodeEncodeError

Opened this issue · 6 comments

Using Python 3.3: got the following error which according to http://stackoverflow.com/a/3224300/1245478 can be fixed with encoding the unicode string as ascii first. The unicode is for a glyph and is defined elsewhere and is correct.

UnicodeEncodeError: 'charmap' codec can't encode character '\ue73d' in position
#1389: character maps to

Traceback (most recent call last):
File "\mincss-script.py", line 9, in load_entry_point('mincss==0.8.1', 'console_scripts', 'mincss')()

File "\main.py", line 70, in main return run(args)

File "\main.py", line 37, in run f.write(link.after)

File "\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]

How did you do this? Can you share the URL you used?

have you got a page (e.g. jsFiddle) I can reproduce that against?

It happens for me in several urls like http://www.yahoo.es

It brokens for me in this rule in my bootstrap.css

a[href^="javascript:"]:after,
a[href^="#"]:after {
  content: "";
}

I had the same problem using Python 2.7. The problem is caused by the fact that the default encoding for io.open is the system prefered encoding. The fix was to declare encoding in io.open as utf-8.

In other words, I changed this line of code:
with io.open(os.path.join(output_dir, orig_name), 'w') as f:

into this line:
with io.open(os.path.join(output_dir, orig_name), 'w', encoding='utf-8') as f:

And of course the same 3 lines below for the "before" case.

Hope this helps.

UnicodeEncodeError: 'charmap' codec can't encode character '\ue73d' in position
#1389: character maps to
Traceback (most recent call last):
File "\mincss-script.py", line 9, in load_entry_point('mincss==0.8.1', 'console_scripts', 'mincss')()
File "\main.py", line 70, in main return run(args)
File "\main.py", line 37, in run f.write(link.after)
File "\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]

yeah the unicode decode eror is quite often with py2.7 .You need to change the encoding to utf-8 to make it working. If it was for py3 it would not be a problem.