error 429, but requests executes the request correctly #9298
-
I'm trying to get a response from a server with a status of 200. The request library handles this, but aiohttp doesn't. import asyncio
import aiohttp
import requests
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0',
'Accept': '*/*',
'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
'Content-Type': 'text/plain;charset=UTF-8',
'Origin': 'https://app.uniswap.org',
}
data = '{"tokenInChainId":1,"tokenIn":"ETH","tokenOutChainId":1,"tokenOut":"0xe41d2489571d322189246dafa5ebde1f4699f498","amount":"1000000000000000000","sendPortionEnabled":true,"type":"EXACT_INPUT","intent":"quote","configs":[{"useSyntheticQuotes":false,"routingType":"DUTCH_V2"},{"enableUniversalRouter":true,"protocols":["V2","V3","MIXED"],"routingType":"CLASSIC","enableFeeOnTransferFeeFetching":true}],"useUniswapX":true,"slippageTolerance":"0.5"}'
def sync_main():
for i in range(10):
s = requests.Session()
s.headers.update(headers)
response = s.post('https://interface.gateway.uniswap.org/v2/quote', data=data)
print("requests ->", response.status_code)
async def async_main():
for i in range(10):
async with aiohttp.ClientSession(headers=headers) as session:
async with session.request("POST",
'https://interface.gateway.uniswap.org/v2/quote',
data=data) as response:
print("aiohttp ->", response.status)
if __name__ == '__main__':
asyncio.run(async_main())
sync_main() Python 3.12 |
Beta Was this translation helpful? Give feedback.
Answered by
webknjaz
Sep 26, 2024
Replies: 1 comment 5 replies
-
You're being rate-limited: |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
webknjaz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're being rate-limited:
429 Too Many Requests
. Wait between the HTTP requests when you see aRetry-After
.