Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.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
Http post在poster中成功,但在python中失败_Python_Http_Github Api - Fatal编程技术网

Http post在poster中成功,但在python中失败

Http post在poster中成功,但在python中失败,python,http,github-api,Python,Http,Github Api,在下面的代码中,我试图用http post创建一个存储库,但我总是收到400个错误请求,当我用poster发送http post时,我创建了201个,这段代码有什么问题 token = raw_input('Access Token: ') url = 'https://api.github.com/user/repos?access_token=' + token values = {"name":"newnewnewnew"} data = urllib.urlencode(values)

在下面的代码中,我试图用http post创建一个存储库,但我总是收到400个错误请求,当我用poster发送http post时,我创建了201个,这段代码有什么问题

token = raw_input('Access Token: ')
url = 'https://api.github.com/user/repos?access_token=' + token
values = {"name":"newnewnewnew"}
data = urllib.urlencode(values)
req = urllib2.Request(url,data)
response = urllib2.urlopen(req)
the_page = response.read();
print the_page
海报:

根据,对于
POST
请求,参数应使用json编码,内容类型应为
application/json

import json

....

token = raw_input('Access Token: ')
url = 'https://api.github.com/user/repos?access_token=' + token
values = {"name": "newnewnewnew"}
data = json.dumps(values)  # <---
req = urllib2.Request(url, data, headers={'Content-Type': 'application/json'})  # <---
response = urllib2.urlopen(req)
the_page = response.read()
print the_page
导入json
....
令牌=原始输入(“访问令牌:”)
url='1〕https://api.github.com/user/repos?access_token=“+代币
值={“name”:“newnew”}
data=json.dumps(值)#