Something very random has happened during my development and I can’t for the life of me figure out what has gone wrong or why.
Im building an application in Flask as well as using Docker. Everything has been running fine up until now.
If I have a file with
And I load the page, the JS will do what you would expect. But then if I add any extra characters to the file,
I get 2 random characters at the end of the file. Both look like
If I was to delete characters from the original file, say
I would get a file with 5 characters missing from the end, so it would look like
As you can see very bizarre.
When running Flask locally everything works fine its only when I load everything into Docker that this starts to happen, so I have to assume its something with Docker & Flask/Python.
The Flask app is started with Gunicorn using default settings, again this has not been an issue in the past.
My Docker environment is run with
docker run -t -i -d --name pv -v $PWD:/app/code -p 5000:5000 -p 5555:5555 --link redis_db:redis_db my_image
Again this hasn’t changed in the last month.
This project is 2+ months old and has been using Docker right from the start with no issues at all.
The only thing that has happened that I can recall since this error has started is that I had to do a Hard GIT Reset to move back one commit.
Things I have already tried.
Using a different IDE to see if it was doing something strange with encoding.
Loading in different browsers. Chrome throws “Uncaught SyntaxError: Unexpected
token ILLEGAL”. And other browsers do similar.
Using an older Docker file.
Loading the script from a different view template.
Honestly I’m at a loss. Any help would be appreciated.
To add to this I only now seem to get the error when running the application using Gunicorn.
You gave the actual byte values as: (239, 191, 189)
This is U+FFFD, the unicode replacement character:
My guess is you’ve written a bad character to the file that your editor is incapable of displaying or editing (as you explained by the weird behavior when adding/removing characters at the end of the file).
>>> data = open('something.js').read() # view the last 8 bytes of the file >>> data[-8:] ... # if you see the last 3 bytes of the file are the bad 239, 191, 189 sequence, # (displayed as "\xef\xbf\xbd" in python), then chop them off: >>> open('something.js', 'w').write(data[:-3]) # or if they occur somewhere else, # use some other string processing to replace them.. >>> open('something.js', 'w').write(data.replace("\xef\xbf\xbd", ""))