GET API代码请求失败

时间:2016-04-06 18:18:56

标签: api python-3.x postman import.io

我刚开始学习如何使用API​​,我发现了一些非常有用的网站和应用程序,如Postman和import.io,但我在没有帮助的情况下完成它时遇到了问题。
我通过从import.io获取一个工作api开始我的小项目(它读取一个网站,可以给你一个工作API,在网站上找到信息)
我的REST API如下所示:

https://extraction.import.io/query/runtime/7629f27e-ceee-4ce2-9a1c-cede623d2fc0?_apikey=[apiKey]&url=http%3A%2F%2Fimdb.com

为了测试并确保它正常工作,我使用了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
}

我做错了什么?

1 个答案:

答案 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"))
相关问题