graphql-python / gql

A GraphQL client in Python

Home Page:https://gql.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when using gqc client under windows

ms140569 opened this issue · comments

When running this program on Windows:

https://github.com/ms140569/omnivore-backup

I'm getting this Error:

python backup.py >outpout.csv
Traceback (most recent call last):
File "\prj\omnivore-backup\backup.py", line 186, in
sys.exit(main())
^^^^^^
File "\prj\omnivore-backup\backup.py", line 67, in main
backup.run()
File "\prj\omnivore-backup\backup.py", line 121, in run
self._fetch()
File "\prj\omnivore-backup\backup.py", line 138, in _fetch
result = self.client.execute(self.query,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\AppData\Roaming\Python\Python312\site-packages\gql\client.py", line 469, in execute
data = loop.run_until_complete(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\asyncio\base_events.py", line 685, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "\AppData\Roaming\Python\Python312\site-packages\gql\client.py", line 367, in execute_async
return await session.execute(
^^^^^^^^^^^^^^^^^^^^^^
File "\AppData\Roaming\Python\Python312\site-packages\gql\client.py", line 1639, in execute
raise TransportQueryError(
gql.transport.exceptions.TransportQueryError: {'message': 'Unexpected server error'}

Yes, the error-message points clearly to a server error, but what made me create this issue is the fact that this only happens on Windows.

There are no problems at all under Linux and Mac. Because of this, I realized this behavior pretty late ...

What could be the reason for this asymmetry?

OS: Win11, Version 10.0.22621 Build 22621
Python: 3.12.2
Gql: 3.5.0
Graphql-core: 3.2.3

Which transport are you using?

You could try activating debug logs to see the message exchanged between gql and the server and compare.

Hi Hanusz,

the transport is the one from the example:

transport = AIOHTTPTransport(self.url, headers={
'Authorization': self.token,
'Content-Type': 'application/json'})

The DEBUG log gives this:

DEBUG:asyncio:Using proactor: IocpProactor
DEBUG:gql.transport.aiohttp:Connecting transport
INFO:gql.transport.aiohttp:>>> {"query": "query Search($query: String!, $first: Int, $after: String) {\n search(query: $query, first: $first, after: $after) {\n ... on SearchSuccess {\n edges {\n cursor\n node {\n title\n url\n labels {\n name\n }\n publishedAt\n savedAt\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n totalCount\n }\n }\n ... on SearchError {\n errorCodes\n }\n }\n}", "variables": {"query": "", "first": 100, "after": ""}}
INFO:gql.transport.aiohttp:<<< {"errors":[{"message":"Unexpected server error"}]}

On Mac the transport response comes instantly:

INFO:gql.transport.aiohttp:<<< {"data":{"search":{"edges":[{"cursor":"100","node":{"title":"E. coli chemotaxis: the baffling intelligence of a single cell","url":"https://jsomers.net/e-coli-chemotaxis/","labels":[{"name":"biology"}],"publishedAt":null,"savedAt":"2024-03-22T05:34:18.000Z"}},{"cursor":"100","node":{"ti
tle":"Melanie Wagner","url":"https:
........

How could the server even know on this level, that he's dealing with another client OS ...?

Are you sure that the token is the same and is extracted correctly on Windows?

Thank you very much - your question made me play around with the token. It was surrounded with a single quote '. This made the token invald.

I never use Windows.

The Error-Message of the Server wasn't that helpful either:

"Unexpected server error"

Sorry for the Noise and thanks again!