[issue20844] SyntaxError: encoding problem: iso-8859-1 on Windows

Steven Winfield report at bugs.python.org
Tue Aug 8 12:06:58 EDT 2017


Steven Winfield added the comment:

I've just been bitten by this on 3.6.2, Windows Server 2008 R2, when running the setup.py script for QuantLib-SWIG:
https://github.com/lballabio/QuantLib-SWIG/blob/v1.10.x/Python/setup.py

It seems there is different behaviour depending on whether:
  * Unix (LF) or Windows (CRLF) line endings are used
  * The file is >4096 bytes or <=4096 bytes
  * The module docstring has an initial space

Some of that has been mentioned previously, but I think the 4096-byte limit might be new, which is why I'm posting.

I've attached a script I used to come up with the results below. It contains:
  * a -*- coding line (for iso-8859-1 in this case)
  * a docstring consisting entirely of lines of x's, of length 78
  * Unix line endings

The file's length is exactly 4096 bytes.

Running this, or slightly modified versions of this, with a 3.6.2 interpreter gave the following results:

  * In all cases, when Windows line endings were used there was no issue - running the script produced no errors or output.

  * With Unix line endings:

    * File length <= 4096, with no leading spaces in the docstring:
	  File "issue20844.py", line 1
	SyntaxError: encoding problem: iso-8859-1

    * File length > 4096, with no leading spaces in the docstring:
	  File "issue20844.py", line 56
		xxxxx"""
			   ^
	SyntaxError: EOF while scanning triple-quoted string literal


    * Any file length, with the first 'x' on line 3 replaced with a space (line 2 if the coding line is ignored):
	  File "issue20844.py", line 2
		xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
		^
	IndentationError: unexpected indent

I had no issues with python 2.7.13.

----------
nosy: +steven.winfield
versions: +Python 3.6
Added file: http://bugs.python.org/file47065/issue20844.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20844>
_______________________________________


More information about the Python-bugs-list mailing list