【发布时间】:2020-11-28 00:48:44
【问题描述】:
我正在尝试从 python/flask webApp 中的 XYZ 提供程序获取 rest api 我将此用作示例/指南 https://help.parsehub.com/hc/en-us/articles/217751808-API-Tutorial-How-to-get-run-data-using-Python-Flask 我没有 api 密钥,但有身份验证令牌,所以这是我正在使用的代码并返回 alldata
`from flask import Flask, render_template
import requests
import json
app = Flask(__name__)
@app.route('/')
def homepage():
headers = {
"Accept": "application/json",
"Authorization": "Bearer MYKEY"
}
r = requests.get(
'https://st1.example.com/restapi/domains/', headers=headers)
return json.loads(r.text)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
`
这会像这样返回所有 json 数据 json image
我喜欢过滤是只显示“域”和“目的地”的一部分,但是当添加这样的代码时
r = requests.get(
'https://st1.example.com/restapi/domains/', headers=headers)
return json.loads(r.text)['destination']
我不断收到“关键错误“目的地””或我输入的任何内容
【问题讨论】:
标签: python python-3.x api flask flask-restful