Skip to content

GitHub API: Server did not return a GraphQL result #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BElluu opened this issue Oct 12, 2020 · 5 comments
Closed

GitHub API: Server did not return a GraphQL result #149

BElluu opened this issue Oct 12, 2020 · 5 comments
Labels
type: question or discussion Issue discussing or asking a question about gql

Comments

@BElluu
Copy link

BElluu commented Oct 12, 2020

Hello,

I want to get some information from Github API. I using your gql. When I do simple request I got "Server did not return a GraphQL result". Do you have any idea what I doing wrong?

from gql import gql, Client, AIOHTTPTransport

URL = "https://api.github.com/graphql"

transport = AIOHTTPTransport(url=URL, headers={'Authorization': 'MY_TOKEN'})

client = Client(transport=transport, fetch_schema_from_transport=True)

query = gql('''
query {
  search(query: "test", type: ISSUE, first: 20) {
    nodes {
      ... on Issue {
        id
        bodyHTML
        title
        url
        closed
      }
    }
  }
}
''')

result = client.execute(query)
print(result)

venv/lib/python3.8/site-packages/gql/transport/aiohttp.py", line 161, in execute
raise TransportProtocolError("Server did not return a GraphQL result")
gql.transport.exceptions.TransportProtocolError: Server did not return a GraphQL result

@leszekhanusz
Copy link
Collaborator

I added some debugging info and tried to use your code (with an invalid token) and I received:

{'message': 'This endpoint requires you to be authenticated.', 'documentation_url': 'https://docs.github.com/v3/#authentication'}

Which is not valid because it does not contain either a data or and errors key in the json. So I received the same error.

I will add more debugging possibilities, but for now, could you please add the following line:
print(f"result={result!r}")
in the gql/transport/aiohttp.py file, just after the line:
result = await resp.json()

So that we can know if you have the same problem.

@leszekhanusz
Copy link
Collaborator

Note: I created a token to test this and now this works for me with your code.

The only modification I made is to add "bearer" before the token:

transport = AIOHTTPTransport(url=URL, headers={'Authorization': 'bearer MY_TOKEN'})

@leszekhanusz leszekhanusz added the status: needs investigation Let's dig deeper into this before drawing conclusions. label Oct 12, 2020
@leszekhanusz
Copy link
Collaborator

I don't know if it is the correct place to report issues to GitHub but I created a post here

@BElluu
Copy link
Author

BElluu commented Oct 12, 2020

@leszekhanusz that's it. I missed "bearer" before my token. I added that and I got correct response. Thank you!
This error message was a bit confusing to me.

@leszekhanusz leszekhanusz added type: question or discussion Issue discussing or asking a question about gql and removed status: needs investigation Let's dig deeper into this before drawing conclusions. labels Oct 12, 2020
@leszekhanusz
Copy link
Collaborator

With PR #155 the message should be more clear:

    raise TransportProtocolError(
gql.transport.exceptions.TransportProtocolError: Server did not return a GraphQL result: No "data" or "error" keys in answer: {"message":"This endpoint requires you to be authenticated.","documentation_url":"https://docs.github.com/v3/#authentication"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about gql
Projects
None yet
Development

No branches or pull requests

2 participants