python - 使用 python (Flask) 从 qwant API 接收数据

标签 python json python-requests

我正在使用这个“API”,据我所知,它只是一个返回 json 数据的链接。关联: https://api.qwant.com/api/search/images?count=10&offset=1&q=stackoverflow

但是,当我尝试访问数据时;

import requests
import json
from flask import Flask, flash, redirect, render_template, request, session, url_for, json, jsonify

@app.route("/display")
def display():
    url = "https://api.qwant.com/api/search/images?count=10&offset=1&q=stackoverflow"
    data = requests.get(url).json()
    return data

我收到以下错误;

simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

而且我似乎找不到解决方法。

最佳答案

您可以解决您的问题,但使用这种类型的 URL:

https://api.qwant.com/api/search/web?count=10&offset=0&q=test&t=web&uiv=1

所以会是:

https://api.qwant.com/api/search/images?count=10&offset=0&q=stackoverflow&t=images&uiv=1

用于您的初始搜索。

只有这样才能从Qwant API获取数据。这样就解决了你的问题。我无法解释为什么我们需要添加这些参数,因为 Qwant API 没有文档,也没有开源。我们可以在 https://github.com/asciimoo/searx/blob/master/searx/engines/qwant.py 上找到此答案的引用/来源。 (正如 https://github.com/asciimoo/searx/issues/1365 所说,今年夏天 Qwant API 发生了变化。)

关于python - 使用 python (Flask) 从 qwant API 接收数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48518860/

相关文章:

python - 类型错误 : forward() missing 1 required positional argument: 'hidden'

Python Sqlalchemy mysql "Cannot add or update a child row: a foreign key constraint fails"

c# - 使用 C# ASP.NET MVC 显示来自单个数组 JSON(azure Cosmos db) 的数据

c# - 反序列化 json 数组以列出 wp7

python请求模块记录编码

python - 从线程停止 WxPython 应用程序的主循环需要窗口焦点

python - 使用另一个列表中的键聚合列表

php - 如何在 NSDictionary 中 POST NSArray of NSDictionaries 而没有问题?

Python请求: "IndexError: list index out of range"

python-3.x - asyncio,将普通函数包装为异步