【发布时间】:2014-11-08 22:20:25
【问题描述】:
我无法使用 github-flask 更新文件。
它给了我一个 404 错误 (https://developer.github.com/v3/troubleshooting/#why-am-i-getting-a-404-error-on-a-repository-that-exists) 但我已经验证我的身份验证令牌是好的并且具有回购范围。我是这样验证的
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'
如果我在帖子中使用参数,双引号不会被转义。 POST 在 curl 上对我来说也失败了,所以我认为我在这里做了一些非常基本的错误?
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"
}
github.get 对于相同的 file_path 有效。
API 列于
https://developer.github.com/v3/repos/contents/#update-a-file
我的应用应该进行代码提交,然后将其部署到其他一些与 github 无关的工作。
【问题讨论】:
-
看起来问题出在 github-flask 库上。我在stackoverflow.com/questions/19888832/… 中的实现之后对其进行了一些修改,现在似乎更好了。经过更多测试后,将在此处更新解决方案和对库的拉取请求,