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

如何用Python 3正确调用PancakeSwap API v2避免500错误?

问题:调用Pancakeswap API v2 summary端点返回500错误

调用的端点:

summary = 'https://api.pancakeswap.info/api/v2/summary'

返回的错误信息:

{'error': {'code': 500, 'message': 'GraphQL error: panic processing query: only derived fields can lead to multiple children here'}}

使用的代码:

import requests
import json

summary = 'https://api.pancakeswap.info/api/v2/summary'

def get_data(endpoint):
    data = requests.get(endpoint).json()
    print(data)

get_data(summary)
解决方案

这个500错误是API服务端内部的GraphQL panic,核心原因是Pancakeswap的API v2版本相关端点已被废弃,不再提供服务。

修复步骤:

  • 替换为当前维护的API v3版本汇总端点,将请求地址改为https://api.pancakeswap.info/api/v3/summary
  • 调整后的代码可以正常获取数据,优化后的代码如下:
import requests

summary = 'https://api.pancakeswap.info/api/v3/summary'

def get_data(endpoint):
    response = requests.get(endpoint)
    if response.status_code == 200:
        data = response.json()
        print(data)
    else:
        print(f"请求失败,状态码:{response.status_code}")

get_data(summary)

建议优先参考Pancakeswap官方最新的API规范,确认接口的可用性,避免调用已下线的端点。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 10:35:26