【发布时间】:2015-01-05 05:39:59
【问题描述】:
我正在尝试使用 python 中的请求将 json 字典发布到 url。我需要从 url 中取回一个字符串,但我不断收到代码 141 错误 -{"code":141,"error":"Missing a github repository link"}。我正在使用这个网站(http://docs.python-requests.org/en/latest/user/quickstart/) 来做请求。
关于为什么我不断收到该错误的任何想法?代码如下。
import requests
import json
payload = { "email" : "jade@gmail.com", "github" : "https://github.com/"}
headers = {'content-type': 'application/json', "Accept": 'application/json'}
r = requests.post("http://challenge.code2040.org/api/register", params = payload, headers = headers)
print(r.url)
print r.text
更新:该建议有效,但现在当我尝试将从 url 收到的响应保存到变量,然后将其发布回不同的 url。
#Store the token into a variable
token = r.text
payload = { "token" : token}
headers = {'content-type': 'application/json', "Accept": 'application/json'}
r = requests.post("http://challenge.code2040.org/api/getstring", json = payload, headers = headers)
print r.text
【问题讨论】: