github - 无法使用 CRUD ( 使用 Flask/python ) 更新github文件

  显示原文与译文双语对照的内容

我无法使用github烧瓶更新文件。

它给我一个 404错误( https://developer.github.com/v3/troubleshooting/#why-am-i-getting-a-404-error-on-a-repository-that-exists ),但是我已经验证了我的认证令牌是好的并且具有 repo 作用域。 我验证了


Anshu-MacBook-Pro:~ anshup$ curl -H"Authorization: token mytoken" https://api.github.com/users/anshprat -I
HTTP/1.1 200 OK
Server: GitHub.com
Date: Fri, 11 Jul 2014 07:21:34 GMT
Content-Type: application/json; charset=utf-8
Status: 200 OK
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4991
X-RateLimit-Reset: 1405065424
Cache-Control: private, max-age=60, s-maxage=60
Last-Modified: Fri, 11 Jul 2014 06:25:54 GMT
ETag:"etag"
X-OAuth-Scopes: repo

我的代码是:


def git_push(file_path,file_path_s,commit_message,raw_file_data):
 u_file_data = base64.b64encode(raw_file_data,salt())
 #print u_file_data
 params = {
 'path':file_path_s
 'message':commit_message,
 'content':u_file_data,
 'sha':file_sha #Its a global variable
 }
 #print raw_file_data,u_file_data,params
 params_json = json.dumps(params)
 return github.post(file_path,params_json) #params fails as well

Flask 帧转储显示:


resource 'repos/anshprat/git-test/contents/play1.txt'

status_code '404'

self <flask_github.GitHub object at 0x2733b90>

response <Response [404]>

kwargs {'headers': {'Content-Type': 'application/x-www-form-urlencoded'}, 'data': '"{"content": "dXNlcjE6cGFzc3dvcmQxCnVzZXIyOnBhc3N3b3JkMgp1c2VyMzpNQlpvRDJLOWJQQS9vCg==", "sha": "ce4979fccba7ef259910c355ca6e1993d7ea436c", "message": "modifying user user3"}"' }

method 'POST'

如果在帖子中使用 params,则双引号不会被转义。 我在卷曲上也失败了,所以我认为我在这里做了一些基本的错误。


 curl -H"Authorization: token mytoken" --data '{"content":"dXNlcjE6cGFzc3dvcmQxCnVzZXIyOnBhc3N3b3JkMgp1c2VyMzpEQXR2VUNweUJrbjdFCg==","message":"modifying user user3","sha":"ce4979fccba7ef259910c355ca6e1993d7ea436c"}' https://api.github.com/repos/anshprat/git-test/contents/play1.txt
{
"message":"Not Found",
"documentation_url":"https://developer.github.com/v3"
}

相同file_path的github.get 。

API列于

https://developer.github.com/v3/repos/contents/#update-a-file

我的应用程序应该执行一个代码提交,然后将它部署到其他非github相关的工作中。

时间:

我必须改变


def post(self, resource, data, **kwargs):
"""Shortcut for ``request('POST', resource)``.
 Use this to make POST request since it will also encode ``data`` to
 'application/x-www-form-urlencoded' format."""
 headers = {'Content-Type': 'application/x-www-form-urlencoded'}


def post(self, resource, data, **kwargs):
"""Shortcut for ``request('POST', resource)``.
 Use this to make POST request since it will also encode ``data`` to
 'application/x-www-form-urlencoded' format."""
 headers = {}
 headers['Content-type'] = 'application/json'
 headers['X-HTTP-Method-Override'] = 'PUT'

因为它工作正常。

...