当使用授权令牌创建存储库“坏凭据”时,git返回401

时间:2017-03-04 16:28:41

标签: github

当我使用关注

curl -i -H 'Authorization: token mytoken' https://api.github.com/user/repos -d '{"name":"REPO2"}'

返回

HTTP/1.1 401 Unauthorized
Server: GitHub.com
Date: Sat, 04 Mar 2017 16:21:13 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 93
Status: 401 Unauthorized
X-GitHub-Media-Type: github.v3; format=json
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 57
X-RateLimit-Reset: 1488646926
Access-Control-Expose-Headers: ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
Access-Control-Allow-Origin: *
Content-Security-Policy: default-src 'none'
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-XSS-Protection: 1; mode=block
X-GitHub-Request-Id: C3B1:3287:955066:BB6710:58BAE978

{
  "message": "Bad credentials",
  "documentation_url": "https://developer.github.com/v3"
}

请帮帮我

1 个答案:

答案 0 :(得分:0)

您可以在Settings > Developer settings > Personal access tokens中创建personal access token并选择repo范围:

enter image description here

然后在您的请求中替换它:

curl -H 'Authorization: token {0123456789zeaz1224334534}' https://api.github.com/{user}/repos -d '{"name":"REPO2"}'