我刚开始学习如何使用API,我发现了一些非常有用的网站和应用程序,如Postman和import.io,但我在没有帮助的情况下完成它时遇到了问题。
我通过从import.io获取一个工作api开始我的小项目(它读取一个网站,可以给你一个工作API,在网站上找到信息)
我的REST API如下所示:
为了测试并确保它正常工作,我使用了postman app,然后找到了一个简洁的功能 - 代码生成。
该应用已生成此代码:
import http.client
conn = http.client.HTTPSConnection("extraction.import.io")
headers = {
'cache-control': "no-cache",
'postman-token': "2087cc79-77b5-0cb9-aa06-adc642978287"
}
conn.request("GET", "/query/runtime/1ac40e3e-f3eb-4290-88c0-e2651b8194a5?_apikey=[apiKey]&url=http%253A%252F%252Fwww.leagueofgraph.com", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
然而结果是:
{
"message" : "Your extraction request has failed.",
"code" : 1003
}
我做错了什么?
答案 0 :(得分:2)
已生成的代码已双重转义“http://”
它应该是http%3A%2F%2F
而不是http%253A%252F%252F
尝试更正此代码:
import http.client
conn = http.client.HTTPSConnection("extraction.import.io")
headers = {
'cache-control': "no-cache",
'postman-token': "2087cc79-77b5-0cb9-aa06-adc642978287"
}
conn.request("GET", "/query/runtime/1ac40e3e-f3eb-4290-88c0-e2651b8194a5?_apikey=[apiKey]&url=http%3A%2F%2Fwww.leagueofgraph.com", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))