2

I'm trying to follow this tutorial: http://tutorial.djangogirls.org/en/index.html

I'm up to this part: http://tutorial.djangogirls.org/en/deploy/README.html

Where I am to push it up to heroku via git. I'm familiar with git just not heroku and while I know python I'm a django beginner.

When I do the command git push heroku master i get this output which prevents the app from being deployed.

Here is the error I am receiving:

(myvenv) $> git push heroku master
Counting objects: 19, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (16/16), done.
Writing objects: 100% (19/19), 3.81 KiB | 0 bytes/s, done.
Total 19 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing runtime (python-3.4.1)
remote: -----> Installing dependencies with pip
remote:        Exception:
remote:        Traceback (most recent call last):
remote:          File "/app/.heroku/python/lib/python3.4/site-packages/pip-      6.0.6-py3.4.egg/pip/basecommand.py", lin
, in main
remote:            status = self.run(options, args)
remote:          File "/app/.heroku/python/lib/python3.4/site-packages/pip-    6.0.6-py3.4.egg/pip/commands/install.py"
e 321, in run
remote:            finder=finder, options=options, session=session):
remote:          File "/app/.heroku/python/lib/python3.4/site-packages/pip-6.0.6-py3.4.egg/pip/req/req_file.py", li
, in parse_requirements
remote:            session=session,
remote:          File "/app/.heroku/python/lib/python3.4/site-packages/pip-  6.0.6-py3.4.egg/pip/download.py", line 4
n get_file_content
remote:            content = f.read()
remote:          File "/app/.heroku/python/lib/python3.4/codecs.py", line   313, in decode
remote:            (result, consumed) = self._buffer_decode(data, self.errors, final)
remote:        UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in      position 0: invalid start byte
remote:
remote:
remote:  !     Push rejected, failed to compile Python app
remote:
remote: Verifying deploy...
remote:
remote: !       Push rejected to chsdjangoblog.
remote:
To https://git.heroku.com/chsdjangoblog.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/chsdjangoblog.git'

does anyone have any idea why this is occurring? heroku seems nice to use, is there a better alternative/what are the best use cases for heroku? I really just want to solve this issue so I can continue the tutorial. Learning django has been a goal of mine for a while as I'm sick of Word Press and PHP development and have been a long time Python lover.

After that error when I try the next step: heroku ps:scale web=1 i get this output:

Scaling dynos... failed
! App mus tbe deployed before dynos can be scaled.

Thanks in advance.

EDIT:

Here's my requirements.txt:

Django==1.8
dj-database-url==0.3.0
gunicorn==19.3.0
heroku==0.1.4
python-dateutil==1.5
requests==2.6.0
whitenoise==1.0.6
psycopg2==2.5.4`

I have tried saving as UTF-8, ANSI, UTF-16. Same message for all of them. I even rewrote it without copy paste. Why is my first byte always 0xff regardless of encoding? What is heroku expecting and is there a way/tool to check the bytes in a txt file?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
ss7
  • 2,902
  • 7
  • 41
  • 90
  • Seems like you have an invalid UTF8 character in your requirements.txt file. Can you try re-saving it as ASCII? – Daniel Roseman Apr 08 '15 at 12:01
  • Same error even with saved as ANSI – ss7 Apr 08 '15 at 12:12
  • Anyway I can track down the culprit? It's one of the dependencies obviously. I am using Python 3.4.1 with ActivePython, would I have better luck using a normal Python release or even switching to Linux? – ss7 Apr 08 '15 at 12:16
  • No, changing the version of Python you use locally wouldn't have any effect on what happens when you push to Heroku. But you should probably paste your requirements.txt file here. – Daniel Roseman Apr 08 '15 at 12:19

3 Answers3

2

On the shoulders of the other contributors to this question, it looks like your requirements.txt file is encoded as UTF-16 little endian.

0xFF is the first character of the Byte Order Mark for UTF-16-LE, the second character being 0xFE. The traceback states that the first character is 0xFF in position 0, and it is common in Windows for files to be stored as UTF-16 with the BOM.

Try saving the requirements.txt file as UTF-8 without BOM, or as ASCII. Simple old notepad.exe might do the trick.

Edit

Not working in notepad, so use Python 3 instead:

with open('requirements.txt', encoding='utf-16') as old, open('requirements_new.txt', 'w', encoding='utf-8') as new:
    new.write(old.read())

requirements_new.txt will now be encoded as UTF-8 and should work (it will probably end up as ASCII anyway).

Note that this is based on the comments and answers of others which have suggested that the troublesome file is requirements.txt.

mhawke
  • 84,695
  • 9
  • 117
  • 138
  • I've tried recreating the file from scratch. With ANSI and UTF-8 in notepad. Still same message with the invalid start byte 0xff. What should the byte be? How can I check/change the start byte? Why is 0xff still the start byte even when I change the coding? – ss7 Apr 08 '15 at 12:46
  • You seem to be steering me in the right direction so thanks. I just don't get why the start byte is invalid in every encoding. What does it expect? – ss7 Apr 08 '15 at 12:54
  • The file is UTF-16. I can't be certain about your environment, nor the editors that you are using. You can open it in Python 3 and save it as UTF-8 as I show in my updated answer. This _should_ get you past the hurdle if `requirements.txt` is the file causing the problem. I'm not positive that it is that file, but the traceback certainly suggests it as do other users. – mhawke Apr 08 '15 at 12:58
1

See this answer: Deploying Django/Python 3.4 to Heroku

pip is crashing because your requirements.txt file is encoded wrong. Save it in UTF-8 ANSI encoding.

Community
  • 1
  • 1
Ayrton Massey
  • 471
  • 3
  • 13
  • tried that, same error. I believe all my files are UTF-8 as that is sublime text's default? – ss7 Apr 08 '15 at 12:04
  • Sorry, the other question actually suggests ANSI encoding. Did you try that? – Ayrton Massey Apr 08 '15 at 12:06
  • You could just open it in Notepad and save it from there. I'm not sure Sublime has that option. – Ayrton Massey Apr 08 '15 at 12:10
  • I got it to save as ANSI but I still get the same error :\ – ss7 Apr 08 '15 at 12:13
  • What shell are you using to output `requirements.txt`? I read that powershell outputs in UTF-16 and you should try creating `requirements.txt` from within `cmd.exe`. – Ayrton Massey Apr 08 '15 at 12:22
  • This is essentially a link-only answer; it should be a comment. – jub0bs Apr 08 '15 at 12:24
  • I used powershell and I read the same thing. I then used notepad to change to ANSI, I'll try doing it from cmd.exe to begin with. -- Tried it, same result – ss7 Apr 08 '15 at 12:30
  • Linked answer isn't of any help really. My answer is what fixed it, however much I hate to answer my own questions, no one else came up with a fix. – ss7 Apr 08 '15 at 16:56
1

I fixed it, the problem seemed to occur only when requirements.txt was generated on windows no matter what encoding I picked. I generated the file in ascii on Linux and it worked. I then transferred the file to windows and it worked there as well. Therefore the problem must be the requirements.txt encoding as was mentioned in comments. However, the correct encoding appears to be ASCII.

ss7
  • 2,902
  • 7
  • 41
  • 90