Skip to content
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

Error 429: catch Retry-After #366

Closed
Hadevmin opened this issue Nov 1, 2022 · 2 comments
Closed

Error 429: catch Retry-After #366

Hadevmin opened this issue Nov 1, 2022 · 2 comments
Labels
type: bug An issue or pull request relating to a bug

Comments

@Hadevmin
Copy link

Hadevmin commented Nov 1, 2022

I would like to know how exploit the return of the server when an error 429 occurs.

I use this template to perform my gql requests:

        async with Client(transport=transport) as session:
            query = gql(query)
            params = {params}
            try:
                result = await session.execute(query, variable_values=params)
            except TransportServerError:
                time.sleep(x_seconds)

I would like to set the x_seconds with the return of the server.

Whenever you perform too many requests, the server will answer with a 429 HTTP error code and add a 'Retry-After: TimeToWaitInSeconds' header to the response. (RFC: https://datatracker.ietf.org/doc/html/rfc6585#section-4)

Should I use the requests library to catch this parameter or can I use the gql library to catch it?

Thanks

@leszekhanusz
Copy link
Collaborator

leszekhanusz commented Nov 7, 2022

You should have the response headers in the transport.response_headers attribute, so you could get the value you're looking for in transport.response_headers["Retry-After"]

This is already working with the RequestsHTTPTransport but for the AIOHTTPTransport the response headers were only saved if there was no error.

The PR #367 should fix this for this transport as well.

@leszekhanusz leszekhanusz added the type: bug An issue or pull request relating to a bug label Nov 7, 2022
@Hadevmin
Copy link
Author

Hadevmin commented Nov 7, 2022

Thanks you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug
Projects
None yet
Development

No branches or pull requests

2 participants