user11972678
user11972678

Reputation: 3

Graphql query in Python

Here is a graphql query with its result : OK.

I try to get the same result with Python, but I get nothing : response.text is empty. (API key is not needed).

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)

Please, any idea ?

Upvotes: 0

Views: 435

Answers (1)

puchal
puchal

Reputation: 2381

It's all good with the query itself. In request you need to pass headers with {'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'}
)

Upvotes: 1

Related Questions