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

Skedulo API查询报错:EQLFilter类型不匹配与TypeError问题求助

问题解决:Skedulo GraphQL查询获取UID并导出CSV的错误修复

错误分析与修复方案

1. GraphQL filter参数类型错误(InstantTag vs StringTag)

Skedulo的GraphQL API要求时间类型的过滤值直接使用ISO 8601格式的裸字符串(不需要加单引号包裹),同时EQL语法中字符串类型的字段值需要用双引号。原代码中给时间值加了单引号,导致API识别为StringTag而非要求的InstantTag。

修复方式:

  • 移除时间值两侧的单引号
  • 将JobStatus的单引号改为双引号(符合EQL语法规范)

2. TypeError: NoneType不可迭代

当GraphQL接口返回错误时,data['data']会是None,此时执行'jobs' in data['data']就会触发该错误。需要先判断data['data']不为None,再检查是否包含jobs字段。

修复方式:

  • 修改判断逻辑为:if 'data' in data and data['data'] is not None and 'jobs' in data['data']

修正后的完整代码

import requests
import json
import pandas as pd
from datetime import datetime, timedelta, timezone

# 计算24小时时间范围
end_time = datetime.now(timezone.utc)
start_time = end_time - timedelta(days=1)
end_time_str = end_time.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z'
start_time_str = start_time.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z'

url = 'https://api.skedulo.com/graphql/graphql'
headers = {'Content-Type': 'application/json', 'Authorization': 'your access token'}

# 修正filter的语法格式
query_1 = {
    "query": f"""
        query {{
            jobs(
                after: null,
                orderBy: "UID",
                filter: "JobStatus == \\"Complete\\" AND ActualEnd >= {start_time_str} AND ActualEnd <= {end_time_str}"
            ) {{
                edges {{
                    cursor
                    node {{
                        UID
                        Name
                    }}
                }}
                pageInfo {{
                    hasNextPage
                }}
            }}
        }}
    """
}

response = requests.post(url, data=json.dumps(query_1), headers=headers, verify=True)
data = response.json()
print(response.content)

uids = []
# 修正空值判断逻辑
if 'data' in data and data['data'] is not None and 'jobs' in data['data']:
    for job in data['data']['jobs']['edges']:
        uids.append(job['node']['UID'])
else:
    print("No valid data found in the response.")

# 将UID导出为CSV
if uids:
    df = pd.DataFrame({"UID": uids})
    df.to_csv("job_uids.csv", index=False)
    print("UID已成功导出到job_uids.csv")

print(uids)

额外说明

  • 确保替换your access token为有效的Skedulo API授权令牌
  • 代码新增了将UID列表导出为CSV的逻辑,满足项目需求

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 04:24:55