git webhook失败了 - 你知道为什么吗?

问题描述 投票:0回答:1

背景:

我有一个名为bitbucketDOSTUFF回购包括一个python脚本do_stuff.py。我在我的本地机器上使用Eclipse pydev编辑它,并通过git push origin master将更改推送到bitbucket。

我将DOSTUFF克隆到pythonanywhere试用帐户,没有任何问题。

现在,每当我在本地编辑do_stuff.py然后将git commit -m 'foo'git push origin master编辑为bitbucket时,我手动需要从pythonanywhere中的git pull以便在pythonanywhere中查看编辑。这is inefficient

目标:

我希望我的本地(Eclipse)提交到bitbucket自动被拉到pythonanywhere一旦从本地推送到bitbucket。显然,webhooks是要走的路。

挑战:

为了做到这一点,我通过在bitbucket中为this指定一个webhook来跟踪pythonanywhere/user/me/webhook.py提示。不幸的是,这些说明是极简主义的,因为他们缺乏适当的进口,并没有阐明为什么需要烧瓶(我不是专家)。

webhook.py看起来像这样:

#!/usr/bin/python2.7
# -*- coding: utf-8 -*

import git
from flask import Flask, request

# Initiate flask instance
app = Flask(__name__)

@app.route('/webhook', methods=['POST'])
def webhook():
    if request.method == 'POST':
        repo = git.Repo('./DOSTUFF')
        origin = repo.remotes.origin
        repo.create_head('master',
    origin.refs.master).set_tracking_branch(origin.refs.master).checkout()
        origin.pull()
        return '', 200
    else:
        return '', 400

if __name__ == '__main__':
    app.run(port=5000,debug=True)

现在,当我从Eclipse到bitbucket的git push时,提交到了bitbucket但是pythonanywhere中的代码保持不变。换句话说,webhook.py失败了。

相反,当我从pythonanywhere(bash控制台)中运行webhook.py时,我产生以下错误:

 * Serving Flask app "__main__" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
Traceback (most recent call last):
  File "/home/ME/webhook.py", line 21, in <module>
    app.run(port=5000,debug=True)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 943, in run
    run_simple(host, port, self, **options)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 795, in run_simple
    s.bind(get_sockaddr(hostname, port, address_family))
  File "/usr/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 98] Address already in use

问题:

失败的根本原因是什么?

如何正确配置一个必要且足以自动git pull的webhook更改为pythonanywhere从本地推送到bitbucket?

python git webhooks continuous-deployment pythonanywhere
1个回答
2
投票

您正在尝试在PythonAnywhere控制台中启动服务器,由于流量未路由到控制台服务器,因此无法运行。使用Web应用程序创建服务器以侦听Web挂钩。

© www.soinside.com 2019 - 2024. All rights reserved.