【问题标题】:Graphql query in PythonPython 中的 Graphql 查询
【发布时间】:2019-08-25 07:39:07
【问题描述】:

Here 是一个 graphql 查询,其结果是:OK。

我尝试使用 Python 获得相同的结果,但我什么也没得到:response.text 为空。 (不需要 API 密钥)。

q = """
{
  node(id: "UXVlc3Rpb25uYWlyZTo5NTNjYjdjYS0xY2E0LTExZTktOTRkMi1mYTE2M2VlYjExZTE=") {
    ... on Questionnaire {
      replies(first: 10, after: null) {
        totalCount
        pageInfo {
          hasNextPage
          endCursor
        }
        edges {
          node {
            id
            createdAt
            publishedAt
            updatedAt
            author {
              id
            }
            responses {
              question {
                title
              }
              ... on ValueResponse {
                value
              }
            }
          }
        }
      }
    }
  }
}
"""

response = requests.post(url = "https://granddebat.fr/graphql" , json = {'query': q})

print(response.text)

请问有什么办法吗?

【问题讨论】:

    标签: python graphql


    【解决方案1】:

    查询本身很好。在请求中,您需要使用 {'Accept': 'application/vnd.cap-collectif.preview+json'} 传递标头

    response = requests.post(
        url = "https://granddebat.fr/graphql",
        json = {'query': q,},
        headers= {'Accept': 'application/vnd.cap-collectif.preview+json'}
    )
    

    【讨论】:

    • 谢谢!!标题没问题!
    猜你喜欢
    • 2020-05-20
    • 1970-01-01
    • 1970-01-01
    • 2021-01-23
    • 2019-09-19
    • 2021-05-21
    • 2020-11-12
    • 2019-05-17
    相关资源
    最近更新 更多