Python 按父级过滤 OData 实体 - 请求库

问题描述 投票:0回答:1

我有一个 OData API,我正在尝试使用 Python 请求库进行查询。我正在尝试根据父表过滤表以进行增量数据拉取。子表不使用

last_update_date
,但我可以从父表获取此日期,因为父表的
last_updated_date
发生更改,即使更改位于子表中也是如此。请注意,在我的示例中,
employees
employee_texts
的父实体。

我的代码如下所示:

data = requests.get(
    endpoint_url + "employee_texts"
    , auth=(api_username, api_password)
    , params={
        "$filter": "employees/LastModifiedDate gt 2023-11-15T00:00:00.00Z",
        "$format": "json"
    }
    , verify=True
)

如果我运行此命令,我会收到以下错误:

{'错误':{'代码':'',
'message': '值不能为空。 参数名称:类型'}}

请注意,此代码按预期工作:

data = requests.get(
    endpoint_url + "employees"
    , auth=(api_username, api_password)
    , params={
        "$filter": "LastModifiedDate gt 2023-11-15T00:00:00.00Z",
        "$format": "json"
    }
    , verify=True
)
python python-requests filtering odata
1个回答
0
投票

如果

employees
是一个集合,那么您需要在
any
查询中使用
$filter
运算符。

data = requests.get(
    endpoint_url + "employee_texts"
    , auth=(api_username, api_password)
    , params={
        "$filter": "employees/any(e:e/LastModifiedDate gt 2023-11-15T00:00:00.00Z)",
        "$format": "json"
    }
    , verify=True
)
© www.soinside.com 2019 - 2024. All rights reserved.