【问题标题】:Heroku and DjangoHeroku 和 Django
【发布时间】:2015-06-13 08:46:10
【问题描述】:

我正在尝试学习本教程: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.

提前致谢。

编辑:

这是我的 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`

我尝试保存为 UTF-8、ANSI、UTF-16。给他们所有人的相同信息。我什至在没有复制粘贴的情况下重写了它。为什么无论编码如何,我的第一个字节总是 0xff? heroku 期待什么,有没有办法/工具来检查 txt 文件中的字节?

【问题讨论】:

  • 您的 requirements.txt 文件中似乎有一个无效的 UTF8 字符。您可以尝试将其重新保存为 ASCII 吗?
  • 同样的错误,即使保存为 ANSI
  • 总之我能找到罪魁祸首吗?这显然是依赖项之一。我正在使用带有 ActivePython 的 Python 3.4.1,使用普通的 Python 版本甚至切换到 Linux 会更好吗?
  • 不,更改本地使用的 Python 版本不会对推送到 Heroku 时发生的情况产生任何影响。但您可能应该在此处粘贴您的 requirements.txt 文件。

标签: python django git heroku


【解决方案1】:

看到这个答案:Deploying Django/Python 3.4 to Heroku

pip 正在崩溃,因为您的 requirements.txt 文件编码错误。保存为 UTF-8 ANSI 编码。

【讨论】:

  • 试过了,同样的错误。我相信我所有的文件都是 UTF-8,因为那是 sublime text 的默认值?
  • 对不起,另一个问题实际上建议使用 ANSI 编码。你试过了吗?
  • 您可以在记事本中打开它并从那里保存。我不确定 Sublime 有这个选项。
  • 我把它保存为 ANSI 但我仍然得到同样的错误:\
  • 你用什么shell来输出requirements.txt?我读到了 UTF-16 中的 powershell 输出,您应该尝试从 cmd.exe 中创建 requirements.txt
【解决方案2】:

在此问题的其他贡献者的肩膀上,您的 requirements.txt 文件似乎被编码为 UTF-16 little endian。

0xFF 是 UTF-16-LE 的 Byte Order Mark 的第一个字符,第二个字符是 0xFE。回溯指出,第一个字符是位置 0 中的 0xFF,在 Windows 中通常将文件存储为带有 BOM 的 UTF-16。

尝试将requirements.txt 文件保存为UTF-8 不带 BOM 或ASCII。简单的旧 notepad.exe 可能会成功。

编辑

无法在记事本中使用,因此请改用 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())

requirements_new.txt 现在将被编码为 UTF-8 并且应该可以工作(它可能最终会以 ASCII 结尾)。

请注意,这是基于 cmets 和其他人的答案,他们认为麻烦的文件是requirements.txt

【讨论】:

  • 我尝试从头开始重新创建文件。在记事本中使用 ANSI 和 UTF-8。具有无效起始字节 0xff 的消息仍然相同。字节应该是什么?如何检查/更改起始字节?为什么更改编码后0xff仍然是起始字节?
  • 你似乎在引导我朝着正确的方向前进,所以谢谢。我只是不明白为什么每个编码中的起始字节都无效。它期待什么?
  • 文件为 UTF-16。我无法确定您的环境,也无法确定您使用的编辑器。您可以在 Python 3 中打开它并将其另存为 UTF-8,如我在更新的答案中所示。如果requirements.txt 是导致问题的文件,这应该 帮助您克服障碍。我不能肯定它就是那个文件,但回溯肯定会像其他用户一样暗示它。
【解决方案3】:

我修好了,问题似乎只有在 windows 上生成 requirements.txt 时才会出现,无论我选择什么编码。我在 Linux 上用 ascii 生成了文件,它工作正常。然后我将文件传输到 Windows,它也在那里工作。因此问题一定是 cmets 中提到的 requirements.txt 编码。但是,正确的编码似乎是 ASCII。

【讨论】:

    猜你喜欢
    • 2018-02-22
    • 2019-08-05
    • 2012-09-14
    • 2014-01-12
    • 2015-11-06
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 2020-05-20
    相关资源
    最近更新 更多