I am trying to implement github webhook to auto run the git pull command when I push out to github. It was working on my local server, but somehow doesn't run on pythonanywhere.
2016-05-25 21:26:55,662 :Exception on /github-update [POST]
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/EndenDragon/APCS_Project/main.py", line 16, in github_update
h = hmac.new(CONFIG_GITHUB_WEBOOK_SECRET, request.get_data(), hashlib.sha1)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/local.py", line 336, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: 'Request' object has no attribute 'get_data'
Here is my code for the github update:
from flask import Flask, request
import hmac
import hashlib
import subprocess
app = Flask(__name__)
@app.route("/github-update", methods=["POST"])
def github_update():
h = hmac.new(CONFIG_GITHUB_WEBOOK_SECRET, request.get_data(), hashlib.sha1)
if h.hexdigest() != request.headers.get("X-Hub-Signature", "")[5:]: # A timing attack here is nearly impossible.
return "FAIL"
try:
subprocess.Popen("git pull", shell=True).wait()
except OSError:
return "ERROR"
return "OK"
So, what happened? Am I doing anything wrong?
EDIT: It worked over here too~ https://github.com/BronyTV/bronytv.net/blob/master/btv_site/app.py#L30