Python-分页“之后”参数在查询中不起作用

发布于 2025-01-20 17:04:41 字数 2334 浏览 0 评论 0原文

我正在制作一个代码以从PipeFy API中获取数据,而分页对我来说并不适合

headers = {
    "authorization": 'Bearer TOKEN',
    "content-type": "application/json"
}
first_query = True
has_next_page = True
pipe_id = "PIPE_ID_NUMBER"
    if first_query:
        payload = "{\"query\":\"{ allCards (pipeId:"+pipe_id+", first:50){edges{node{id title fields {report_value updated_at}} cursor} pageInfo {endCursor hasNextPage}}}\"}"
        print(payload)
        first_query = False
    else:
        payload = "{\"query\":\"{allCards(pipeId:"+pipe_id+",after:\""+end_cursor+"\"){edges{node{id title fields{report_value updated_at}}}pageInfo{endCursor hasNextPage}}}\"}"
        print(payload)
    response = requests.request("POST", url, data=payload, headers=headers)
    print(response)    
    json_data = json.loads(response.text)
    end_cursor = json_data["data"]["allCards"]["pageInfo"]["endCursor"]
    has_next_page = json_data["data"]["allCards"]["pageInfo"]["hasNextPage"]
    total_records_pg = len(json_data["data"]["allCards"]["edges"])

,我得到了回报:

{"query":"{ allCards (pipeId:PIPE_ID, first:50){edges{node{id title fields {report_value updated_at}} cursor} pageInfo {endCursor hasNextPage}}}"}
<Response [200]>
{"query":"{allCards(pipeId:PIPE_ID,after:"WyIyLjAiLCItNTcuMCIsNTA0NDMxMzg4XQ"){edges{node{id title fields{report_value updated_at}}}pageInfo{endCursor hasNextPage}}}"}
<Response [400]>
Traceback (most recent call last):
  File "c:\Users\rafael.alves\Desktop\Novo PC\uknow\DigitalPE\import requests.py", line 32, in <module>
    json_data = json.loads(response.text)
  File "C:\Users\rafael.alves\AppData\Local\Programs\Python\Python310\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "C:\Users\rafael.alves\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\rafael.alves\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
PS C:\Users\rafael.alves\Desktop\Novo PC\uknow> 

到处都在我弄错的地方,但没有成功。 “&lt;响应[400]&gt;”告诉我,有效载荷只是将空的空白带来,我认为这意味着错误是“之后”的论点

Im making a code to get data from pipefy API and the pagination isn't working out for me

headers = {
    "authorization": 'Bearer TOKEN',
    "content-type": "application/json"
}
first_query = True
has_next_page = True
pipe_id = "PIPE_ID_NUMBER"
    if first_query:
        payload = "{\"query\":\"{ allCards (pipeId:"+pipe_id+", first:50){edges{node{id title fields {report_value updated_at}} cursor} pageInfo {endCursor hasNextPage}}}\"}"
        print(payload)
        first_query = False
    else:
        payload = "{\"query\":\"{allCards(pipeId:"+pipe_id+",after:\""+end_cursor+"\"){edges{node{id title fields{report_value updated_at}}}pageInfo{endCursor hasNextPage}}}\"}"
        print(payload)
    response = requests.request("POST", url, data=payload, headers=headers)
    print(response)    
    json_data = json.loads(response.text)
    end_cursor = json_data["data"]["allCards"]["pageInfo"]["endCursor"]
    has_next_page = json_data["data"]["allCards"]["pageInfo"]["hasNextPage"]
    total_records_pg = len(json_data["data"]["allCards"]["edges"])

and i got the return:

{"query":"{ allCards (pipeId:PIPE_ID, first:50){edges{node{id title fields {report_value updated_at}} cursor} pageInfo {endCursor hasNextPage}}}"}
<Response [200]>
{"query":"{allCards(pipeId:PIPE_ID,after:"WyIyLjAiLCItNTcuMCIsNTA0NDMxMzg4XQ"){edges{node{id title fields{report_value updated_at}}}pageInfo{endCursor hasNextPage}}}"}
<Response [400]>
Traceback (most recent call last):
  File "c:\Users\rafael.alves\Desktop\Novo PC\uknow\DigitalPE\import requests.py", line 32, in <module>
    json_data = json.loads(response.text)
  File "C:\Users\rafael.alves\AppData\Local\Programs\Python\Python310\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "C:\Users\rafael.alves\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\rafael.alves\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
PS C:\Users\rafael.alves\Desktop\Novo PC\uknow> 

have looking everywhere where i got it wrong but no with no succes.
the "<Response [400]>" tells me that the payload just bring empty, and i supossed that means the mistake is the "after" argument

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哭泣的笑容 2025-01-27 17:04:42

我成功了

 if first_query:
        payload = "{\"query\":\"{ allCards (pipeId:%d, first:50){edges{node{id title phases_history {phase{name}}fields {report_value   name updated_at}} cursor} pageInfo {endCursor hasNextPage}}}\"}" % (
            pipe_id)
        first_query = False
    else:
        payload = '{"query": "{allCards(pipeId: %d,after: \\"%s\\"){edges{node{id title phases_history {phase{name}} fields{report_value name updated_at}}}pageInfo{endCursor hasNextPage}}}"}' % (
            pipe_id, end_cursor)

I made it work

 if first_query:
        payload = "{\"query\":\"{ allCards (pipeId:%d, first:50){edges{node{id title phases_history {phase{name}}fields {report_value   name updated_at}} cursor} pageInfo {endCursor hasNextPage}}}\"}" % (
            pipe_id)
        first_query = False
    else:
        payload = '{"query": "{allCards(pipeId: %d,after: \\"%s\\"){edges{node{id title phases_history {phase{name}} fields{report_value name updated_at}}}pageInfo{endCursor hasNextPage}}}"}' % (
            pipe_id, end_cursor)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文