Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python使用请求模块从github删除repo_Python_Django_Api_Github_Repository - Fatal编程技术网

Python使用请求模块从github删除repo

Python使用请求模块从github删除repo,python,django,api,github,repository,Python,Django,Api,Github,Repository,在这种情况下,我不需要编写代码。 我可以使用request.post()在python中创建一个存储库,但我不能删除该存储库中的一个文件 代码如下: def deleteRepository(self, repo, name): headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': 'token {}'.format(self.token)} resp

在这种情况下,我不需要编写代码。
我可以使用
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)
打印(响应状态\ U代码)
请注意
'/repos/'+username+'/'+name+'
部分:分隔符对于您的应用程序非常重要


2021年6月更新:如“”中所述

如果您当前正在进行类似的API调用

curl "https://api.github.com/user/repos?access_token=my_access_token"
相反,您应该在标头中发送令牌:

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'})
打印(响应状态\ U代码)

我照你说的做了,问题解决了。非常感谢。你测试过了吗<代码>。必须通过授权标头指定访问令牌…更改/2020-02-10-弃用@Timo它当时起作用,但可能:或者更确切地说,@Timo我已经相应地编辑了答案。