我正试图遵循本教程:http://tutorial.djangogirls.org/en/index.html
我来演这个角色:http://tutorial.djangogirls.org/en/deploy/README.html
我要通过Git把它推到Heroku。我熟悉git,但不熟悉heroku,虽然我了解python,但我是django初学者。
当我执行命令git push heroku master
时,我得到这个输出,它阻止应用程序被部署。
以下是我收到的错误:
(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'
有人知道为什么会这样吗?heroku似乎很好用,有没有更好的选择/heroku的最佳用例是什么?我真的只想解决这个问题,以便我可以继续教程。学习django一直是我的一个目标,因为我厌倦了word press和php开发,并且长期以来都是python爱好者。
在这个错误之后,当我尝试下一步时:
heroku ps:scale web=1
我得到这个输出:Scaling dynos... failed
! App mus tbe deployed before dynos can be scaled.
提前谢谢。
编辑:
这是我的要求.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`
我试过保存为utf-8,ansi,utf-16。对所有人来说都是同样的信息。我甚至重写它没有复制粘贴。为什么我的第一个字节总是0xFF而不考虑编码?Heroku期望什么,是否有方法/工具检查TXT文件中的字节?
最佳答案
在这个问题的其他贡献者的肩上,看起来您的requirements.txt
文件被编码为utf-16 little endian。0xFF
是utf-16-le的Byte Order Mark的第一个字符,第二个字符是0xFE
。回溯指出,第一个字符在位置0处是0xFF,在Windows中,文件与bom一起存储为utf-16是很常见的。
尝试将requirements.txt
文件保存为不带bom的utf-8或ascii。简单的“老”可能会成功。
编辑
不在记事本中工作,因此改用python 3:
with open('requirements.txt', encoding='utf-16') as old, open('requirements_new.txt', 'w', encoding='utf-8') as new:
new.write(old.read())
notepad.exe
现在将被编码为utf-8并且应该可以工作(它可能最终会以ascii结束)。请注意,这是基于其他人的评论和回答,他们建议麻烦的文件是
requirements_new.txt
。关于python - Heroku和Django,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29513875/