2

I'm trying to call sass from python and I'm struggling to make it work.

If I run the following command from my CLI it works:

sass /path/to/style.scss /path/to/style.css --style=compressed

This works until I try to call it through my python script:

import subprocess
subprocess.check_output(['sass', '/path/to/style.scss', '/path/to/style.css', '--style=compressed'])

I get the following error:

Syntax error: Invalid US-ASCII character "\xE2"

I've read that I can fix this by adding @charset "UTF-8"; at the top of each file that has encoding errors.

The problem is there are lots of files and many are in bower packages so adding to them is not the best solution.

I've read that I can append the following option to sass: --default-encoding="UTF-8", but when I try this I get this error both on the CLI and in Python:

ArgumentError: unknown encoding name - "UTF-8"

Anyone know any other workarounds, or why it would work on the CLI and not by calling it via python?

Dustin
  • 3,965
  • 5
  • 27
  • 33

2 Answers2

2

try this:

sass --default-encoding UTF-8 
mMo
  • 233
  • 2
  • 10
0

SASS docs say on this:

Encodings

When running on Ruby 1.9 and later, Sass is aware of the character encoding of documents. Sass follows the CSS spec to determine the encoding of a stylesheet, and falls back to the Ruby string encoding. This means that it first checks the Unicode byte order mark, then the @charset declaration, then the Ruby string encoding. If none of these are set, it will assume the document is in UTF-8.

To explicitly specify the encoding of your stylesheet, use a @charset declaration just like in CSS. <...>

So, you have a whole bunch of options here.

For the "Ruby string encoding" part, see Set UTF-8 as default for Ruby 1.9.3 .

Community
  • 1
  • 1
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152