peterbe / mincss

Tool for finding out which CSS selectors you're NOT using.
https://peterbe.github.io/mincss/
BSD 3-Clause "New" or "Revised" License
854 stars 92 forks source link

UnicodeEncodeError #21

Open meishern opened 10 years ago

meishern commented 10 years ago

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]

peterbe commented 10 years ago

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

peterbe commented 10 years ago

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

coolxeo commented 10 years ago

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

coolxeo commented 10 years ago

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

a[href^="javascript:"]:after,
a[href^="#"]:after {
  content: "";
}
PeterLazar commented 9 years ago

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.

arpit1997 commented 7 years ago

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.