【问题标题】:git webhook fails - do you know why?git webhook 失败 - 你知道为什么吗?
【发布时间】:2019-09-17 04:37:44
【问题描述】:

背景:

我有一个名为DOSTUFFbitbucket 存储库,其中包含一个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 的提交在从本地推送到 bitbucket 后自动拉到 pythonanywhere。显然,webhooks 是要走的路。

挑战:

为了做到这一点,我遵循this 的提示,将bitbucket 中的一个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)

现在,当我 git push 从 Eclipse 到 bitbucket 时,提交到达 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

问题:

失败的根本原因是什么?

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

【问题讨论】:

    标签: python git webhooks continuous-deployment pythonanywhere


    【解决方案1】:

    您正在尝试在 PythonAnywhere 控制台中启动服务器,但由于流量未路由到控制台服务器,该服务器无法正常工作。使用 Web 应用创建服务器以侦听 Web 挂钩。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-24
      • 2014-04-08
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-17
      • 1970-01-01
      相关资源
      最近更新 更多