I am trying to automatically pull changes from my origin in github to the web app in pythonanywhere using webhooks. Repo was cloned using ssh. ssh keys are added to ssh-agent.
I have my pythonanywhere public SSH key stored with github as deploy key. When pushes are made to the origin on github, the webhook sends POST request to my /update_server/ url. The view function looks like this:
@csrf_exempt
def update(request):
if request.method == "POST"
repo = git.Repo("/repo_dir/")
origin = repo.remotes.origin
origin.pull()
return HttpResponse("Updated code on PythonAnywhere")
else:
return HttpResponse("Couldn't update the code on PythonAnywhere")
The webhook works fine with simple ping, so that functionality is working. The url also works ok. But I keep getting the below 500 Internal Service Error when I try to execute the process from github.
2020-04-28 14:04:13,397: Internal Server Error: /update_server/
Traceback (most recent call last):
File "/home/deasunod/.virtualenvs/myenv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/deasunod/.virtualenvs/myenv/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/deasunod/.virtualenvs/myenv/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/deasunod/.virtualenvs/myenv/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/home/deasunod/ppr_corona/main/views.py", line 228, in update
origin.pull()
File "/home/deasunod/.virtualenvs/myenv/lib/python3.7/site-packages/git/remote.py", line 812, in pull
res = self._get_fetch_info_from_stderr(proc, progress)
File "/home/deasunod/.virtualenvs/myenv/lib/python3.7/site-packages/git/remote.py", line 676, in _get_fetch_info_from_stderr
proc.wait(stderr=stderr_text)
File "/home/deasunod/.virtualenvs/myenv/lib/python3.7/site-packages/git/cmd.py", line 408, in wait
raise GitCommandError(self.args, status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
cmdline: git pull -v origin
stderr: 'fatal: Could not read from remote repository.
**NO MATCH**
Please make sure you have the correct access rights
and the repository exists.'
Any help or ideas would be greatly appreciated!