To reproduce, create an ASCII file with > io.DEFAULT_BUFFER_SIZE bytes (can be blank lines) and *UNIX line endings*, with the first two lines reading:
#!/usr/bin/env python
# -*- coding: cp1252 -*-
Try to run this as a script on Windows:
C:\Python35\python.exe encoding-problem-cp1252.py
File "encoding-problem-cp1252.py", line 2
SyntaxError: encoding problem: cp1252
Converting the file to use CRLF (Windows) line endings makes the problem go away.
This appears to be a fallout from issue #20731.
Demo file that reproduces this issue at 710 bytes: https://github.com/techtonik/testbin/raw/fbb8aec3650b45f690c4febfd621fe5d6892b14a/python/encoding-problem-cp1252.py
First reported by anatoly techtonik at https://stackoverflow.com/questions/39032416/python-3-5-syntaxerror-encoding-prob-em-cp1252 |