下面是我的python脚本,用于打印Github存储库的所有协作者。我收到了响应403错误。我不知道我应该在这里使用哪个令牌。它是个人令牌,OAuth令牌。有人可以指导我如何在这里生成访问令牌吗?
# coding: utf-8
import requests
import sys
import json
from pprint import pprint
import codecs
#sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
headers = {'Accept':'application/vnd.github.hellcat-preview+json'}
LIST_REPOSITORIES_API = 'https://api.github.com/repos/d3/d3'
LIST_COLLABORATORS_API = 'https://api.github.com/repos/%s/collaborators'
if __name__ == '__main__':
headers['Authorization'] = 'token %s' % 'my_token'
# get repositories
res = requests.get(LIST_REPOSITORIES_API)
print(res)
repos = res.json()
# get collaborators
repos2collaborators = []
collaborators2repos = {}
print(type(repos))
print(repos)
full_name = repos['full_name']
print(full_name)
#res1 = requests.get(LIST_COLLABORATORS_API, headers=headers)
#print(res1)
res = requests.get(LIST_COLLABORATORS_API % full_name, headers=headers)
print(res)