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

使用Frankfurter API与Python虚拟环境时遭遇404错误

问题解决指南

API 404错误修复

Frankfurter API已更新端点结构,旧的无版本号/latest端点已被移除,必须使用带版本前缀的正确路径。修改请求URL如下:

response = requests.get(f"https://api.frankfurter.app/v1/latest?amount={amount}&from={CF}&to={CT}")

同时建议添加错误处理逻辑,避免因API返回异常触发KeyError:

response = requests.get(f"https://api.frankfurter.app/v1/latest?amount={amount}&from={CF}&to={CT}")
if response.status_code == 200:
    data = response.json()
    print(f"{amount} {CF} is {data['rates'][CT]} {CT}")
else:
    print(f"请求失败,状态码: {response.status_code},错误信息: {response.json().get('message', '未知错误')}")

虚拟环境不稳定问题排查

  • 确认VS Code已正确激活虚拟环境:查看左下角状态栏的Python解释器路径,确保指向你的虚拟环境目录(如./venv/Scripts/python.exe)
  • 检查虚拟环境的Python版本与项目要求一致:运行python --version对比全局版本
  • 用依赖列表统一安装,避免版本冲突:
    # 导出当前依赖到文件
    pip freeze > requirements.txt
    # 重建虚拟环境后重新安装
    pip install -r requirements.txt
    
  • 清理pip缓存解决安装异常:
    pip cache purge
    

内容的提问来源于stack exchange,提问作者imsolost

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 08:12:33