You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

密歇根大学Python课程Runstone环境中TasteDive API返回HTML问题求助

密歇根大学Runstone环境下TasteDive API调用问题排查与适配指导

问题背景

我在密歇根大学《Python数据采集与处理》课程的Runstone代码环境中完成作业,需调用TasteDive API,但接口返回HTML响应而非预期的JSON,导致无法正常解析。作业提示TasteDive API已失效,但使用requests_with_caching.get()在Runstone环境仍可使用,按要求编写代码后仍持续获取HTML响应,尝试标准requests.get()也未成功。

相关代码

import requests_with_caching
import json 

def get_movies_from_tastedive(movie_name):
    baseurl = "https://tastedive.com/api/similar"
    params = {
        'q': movie_name,
        'type': 'movies',
        'limit': 5,
    }

    tastedive_resp = requests_with_caching.get(baseurl, params=params, permanent_cache_file="tastedive_cache.txt")
    
    try:
        tastedive_data = tastedive_resp.json()
        print(json.dumps(tastedive_data, indent=2))  # 打印完整响应用于分析
        return tastedive_data['Similar']['Results']
    except KeyError:
        print(f"错误:无法从TasteDive获取数据 {KeyError}")
        print(tastedive_resp.text)
        return None
    
get_movies_from_tastedive("Bridesmaids")
get_movies_from_tastedive("Black Panther")

报错信息

new; adding to cache
{"error":"Response not interpretable as json. Try printing the .text attribute"}
Error: Unable to fetch data from TasteDive <class 'KeyError'>

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 01:10:02