Setting cookies in AIOHttpTransport doesn't work
See original GitHub issueI’m trying to set cookies in the transport to execute a query.
This works when I use RequestsHTTPTransport
but not when I use AIOHTTPTransport
.
The cookie needs to be present in the POST request. In case it’s not present, the client gets redirected to the login page.
So if I’m using requests
library directly, it should look like this:
cookies = authenticate(url, username, password)
json = { 'query' : '{ queryName { id }}' }
r = requests.post(url, json=json, cookies=cookies)
This works:
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
from gql.transport.requests import RequestsHTTPTransport
cookies=authenticate(url, username, password).get_dict()
transport = RequestsHTTPTransport(url=url, timeout=900, cookies=cookies)
with Client(
transport=transport,
# fetch_schema_from_transport=True,
execute_timeout=1200,
) as client:
query = gql('''
query {
queryName { id }
}
''')
result = client.execute(query)
print(result)
This redirects me to the login page.
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
cookies=authenticate(url, username, password).get_dict()
transport = AIOHTTPTransport(url=url, timeout=900, cookies=cookies)
async with Client(
transport=transport,
# fetch_schema_from_transport=True,
execute_timeout=1200,
) as client:
query = gql('''
query {
queryName { id }
}
''')
result = await client.execute(query)
print(result)
I need to send the same cookies for uploading a file via graphQL which is why I need to use AIOHttpTransport
. How do I send cookies the same way as in requests?
Note: Tried sending via extra_args
but that didn’t work.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11
Top Results From Across the Web
Setting cookies in AIOHTTPTransport doesn't work
I'm trying to set cookies in the transport to execute a query using gql. This works when I use RequestsHTTPTransport but not when...
Read more >AIOHTTPTransport — gql 3 3.0.0 documentation
Using HTTP Cookies. You can manually set the cookies which will be sent with each connection: transport = AIOHTTPTransport(url=url, cookies={"cookie1": ...
Read more >Cookie not shown/stored in the browser - Help - Apollo GraphQL
My problem with it is that in apollo studio my cookie, which is created inside the UserResolver under the mutation login, isn't shown...
Read more >Use Neptune graph notebooks to get started quickly
You don't have to use Neptune graph notebooks to work with a Neptune graph, ... You can use the Neptune console to set...
Read more >GraphQL API - Ghostwriter
Unlike a REST API, a GraphQL API does not have specific endpoints you must query with a particular HTTP request type to receive...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry, posted previous message without page reload.
Thank you very much, you save my day, thats works perfect!
As i can see, there are some unexpected features in aiohttp with SimpleCookie, because sometimes cookies are enclosed with quotes e.t.c. There are some issues in aiohttp repo https://github.com/aio-libs/aiohttp/issues/5397 So, i guess, authors problem is also caused by using cookies without CookieJar.
I added some documentation about this in PR #202