Python 使用请求模块从 github 中删除一个 repo
Python deleting a repo from github with request module
我不会编码这种情况。
我可以使用 request.post()
在 python 中创建存储库,但我无法删除此存储库。
代码如下:
def deleteRepository(self, repo, name):
headers = {'Accept': 'application/vnd.github.v3+json',
'Authorization': 'token {}'.format(self.token)}
response = requests.delete(self.api_url + '/repos/' + name + repo, headers = headers)
return response.json()
+ name + repo
好像很奇怪。
def deleteRepository(self,name,username):
response = requests.delete(self.api_url+'/repos/' + username + '/'+name+'?access_token='+self.token)
print(response.status_code)
请注意 '/repos/' + username + '/'+name+'
部分:分隔符对您的 path segments 很重要。
2021 年 6 月更新:如“中所述
通过查询参数弃用 API 身份验证 "
If you're currently making an API call similar to
curl "https://api.github.com/user/repos?access_token=my_access_token"
Instead, you should send the token in the header:
curl -H 'Authorization: token my_access_token' https://api.github.com/user/repos
所以:
def deleteRepository(self,name,username):
response = requests.delete(self.api_url+'/repos/' + username + '/'+name+', headers={'Authorization': 'token self.token'})
print(response.status_code)
我不会编码这种情况。
我可以使用 request.post()
在 python 中创建存储库,但我无法删除此存储库。
代码如下:
def deleteRepository(self, repo, name):
headers = {'Accept': 'application/vnd.github.v3+json',
'Authorization': 'token {}'.format(self.token)}
response = requests.delete(self.api_url + '/repos/' + name + repo, headers = headers)
return response.json()
+ name + repo
好像很奇怪。
def deleteRepository(self,name,username):
response = requests.delete(self.api_url+'/repos/' + username + '/'+name+'?access_token='+self.token)
print(response.status_code)
请注意 '/repos/' + username + '/'+name+'
部分:分隔符对您的 path segments 很重要。
2021 年 6 月更新:如“中所述 通过查询参数弃用 API 身份验证 "
If you're currently making an API call similar to
curl "https://api.github.com/user/repos?access_token=my_access_token"
Instead, you should send the token in the header:
curl -H 'Authorization: token my_access_token' https://api.github.com/user/repos
所以:
def deleteRepository(self,name,username):
response = requests.delete(self.api_url+'/repos/' + username + '/'+name+', headers={'Authorization': 'token self.token'})
print(response.status_code)