Python-分页“之后”参数在查询中不起作用
我正在制作一个代码以从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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我成功了
I made it work