Git Heroku 错误 [remote rejected] ... (pre-receive hook declined)。

3
我正试图将本地代码库(repo)推送到我的Heroku服务器上,但每次都会出现以下错误:
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/my-heroku-project.git'

这是Python版本3.8.0的完整命令行日志:

Enumerating objects: 36, done.
Counting objects: 100% (36/36), done.
Delta compression using up to 8 threads
Compressing objects: 100% (27/27), done.
Writing objects: 100% (36/36), 4.63 MiB | 923.00 KiB/s, done.
Total 36 (delta 9), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: /app/tmp/buildpacks/8790c95df255b386056ea169648fd4a33d1cb3fba81f73b536f26374f6af107145f64a5980db7a52177f63bb41527f360ebd2e3bef7b8917bda7b51cf284cfdb/bin/steps/python: line 5: warning: command substitution: ignored null byte in input
remote:  !     Requested runtime (ÿþPython-3.8.0) is not available for this stack (heroku-18).
remote:  !     Aborting.  More info: https://devcenter.heroku.com/articles/python-support
remote:  !     Push rejected, failed to compile Python app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to my-heroku-project.
remote:
To https://git.heroku.com/whatsapp-vertretungsplan-bot.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/my-heroku-project.git'

以下是Python版本3.7.5的完整命令行日志:

Enumerating objects: 40, done.
Counting objects: 100% (40/40), done.
Delta compression using up to 8 threads
Compressing objects: 100% (30/30), done.
Writing objects: 100% (40/40), 4.63 MiB | 910.00 KiB/s, done.
Total 40 (delta 11), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: /app/tmp/buildpacks/8790c95df255b386056ea169648fd4a33d1cb3fba81f73b536f26374f6af107145f64a5980db7a52177f63bb41527f360ebd2e3bef7b8917bda7b51cf284cfdb/bin/steps/python: line 5: warning: command substitution: ignored null byte in input
remote:  !     Requested runtime (ÿþPython-3.7.5) is not available for this stack (heroku-18).
remote:  !     Aborting.  More info: https://devcenter.heroku.com/articles/python-support
remote:  !     Push rejected, failed to compile Python app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to my-heroku-project.
remote:
To https://git.heroku.com/whatsapp-vertretungsplan-bot.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/my-heroku-project.git'

(这是我第一次使用Git和Heroku,所以如果错误很明显,我很抱歉。)

但是我已经尝试过Python 3.7.5和Python 2.7.17,但两者都无法工作,尽管它们在herokustack-18上被列为支持的。 - stuchlyf
1
你应该仔细检查你的 runtime.txt 文件;ÿþPython-3.7.5 不符合 https://devcenter.heroku.com/articles/python-runtimes 中的要求。 - jonrsharpe
1
好的,文档指出它是区分大小写的;还有一些额外的字符来自某个地方 - jonrsharpe
现在我已经将 runtime.txt 文件名全部改为小写,但在命令行中仍然是 ÿþpython-3.7.5 - stuchlyf
2
请参见 https://stackoverflow.com/search?q=%C3%BF%C3%BE - jonrsharpe
显示剩余3条评论
10个回答

1
在 runtime.txt 文件中,Python 是怎么写的?是 Python 还是 python?我遇到了这个问题:我从 Python-3.8.0 改成了 python-3.8.0,然后它就可以工作了。

1

对我有效的方法是这个pip freeze > requirements.txt

我意识到我一直忘记添加requirements文件。

之后,请按照以下顺序重复执行。

git add .
git commit -am "make it better"
git push heroku master

0
在大多数情况下,您只需使用以下方法禁用静态文件配置即可:
heroku config:set DISABLE_COLLECTSTATIC=1

你就可以开始了。


0
我通过创建 runtime.txt 文件并将我想要的 Python 版本 (python-3.7.11) 写入该文件中,然后将其与 app.py 放置在同一目录下来解决了这个问题。
app.py
Procfile
requirements.txt
runtime.txt

0

我成功解决了这个问题,以下是我的步骤:

  • pip freeze > requirements.txt
  • git add .
  • git commit -am "make it better"

最后我再次进行了推送:

  • git push heroku master
remote: -----> Installing requirements with pip
remote:        Collecting click==8.0.3
remote:          Downloading click-8.0.3-py3-none-any.whl (97 kB)
remote:        Collecting Flask==2.0.2
remote:          Downloading Flask-2.0.2-py3-none-any.whl (95 kB)
remote:        Collecting gunicorn==20.1.0
remote:          Downloading gunicorn-20.1.0-py3-none-any.whl (79 kB)
remote:        Collecting itsdangerous==2.0.1
remote:          Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
remote:        Collecting Jinja2==3.0.3
remote:          Downloading Jinja2-3.0.3-py3-none-any.whl (133 kB)
remote:        Collecting MarkupSafe==2.0.1
remote:          Downloading MarkupSafe-2.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30 kB)
remote:        Collecting Werkzeug==2.0.2
remote:          Downloading Werkzeug-2.0.2-py3-none-any.whl (288 kB)
remote:        Installing collected packages: MarkupSafe, Werkzeug, Jinja2, itsdangerous, click, gunicorn, Flask
remote:        Successfully installed Flask-2.0.2 Jinja2-3.0.3 MarkupSafe-2.0.1 Werkzeug-2.0.2 click-8.0.3 gunicorn-20.1.0 itsdangerous-2.0.1
remote: -----> Skipping Django collectstatic since the env var DISABLE_COLLECTSTATIC is set.
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing...
remote:        Done: 62.3M
remote: -----> Launching...
remote:        Released v4
remote:        https://flask-heru.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/flask-heru.git
 * [new branch]      master -> master

0

以“remote:”开头的行是远程存储库中的pre-receive hook回显。远程存储库运行hook以在接受您的推送之前检查文件。它尝试构建/解析文件并遇到错误... 您可以在此处找到完整的答案。 Heroku部署问题([remote rejected] master -> master(pre-receive hook declined)error:failed to push some refs)

对于我的情况,我正在尝试部署一个flask应用程序,但缺少一个包含必要依赖项的文件。为了纠正错误,我执行了以下操作以生成包含所有依赖项的文件。“pip freeze > requirements.txt”,然后问题就解决了。

以下博客详细介绍了如何在Heroku上部署Flask应用程序。 https://medium.com/the-andela-way/deploying-a-python-flask-app-to-heroku-41250bda27d0


0
在我的情况下,我意识到我忘记通过终端登录Heroku了。然后我更新了requirements.txt文件。
这是我所做的:
  1. heroku login
  2. git add .
  3. git commit -m "requirements.txt updates"
  4. git push heroku master.
它按照我预期的工作了。

0

查看您的仪表板 -> YOUR_APP -> 活动 -> 查看日志

您可以找到确切的错误消息。

在我的情况下,我发现了这个(查看图片),我不得不删除我的package-lock.json,因为我也有yarn.lock...

enter image description here


0

我找到了问题所在。

我认为Heroku不支持我的编码类型,因此它向我的runtime.txt添加了一些奇怪的字符。但是在更改为UTF-8(我想是这个,很久以前了),一切都运行正常。


0

对我有效

首先

$ heroku config:set DISABLE_COLLECTSTATIC=1

之后

$ git push heroku main

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接