I'm trying to get some data from pubg API using requests.get()
.
While code was executing, response.status_code
returned 429
.
After I got 429
, I couldn't get 200
.
how to fix this situation?
Here is part of my code.
for num in range(len(platform)):
url = "https://api.pubg.com/shards/"+platform[num]+"/players/"+playerID[num]+"/seasons/"+seasonID+"/ranked"
req = requests.get(url, headers=header)
print(req.status_code)
[output]
200
429
As per https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429
you are sending too many requests at once/in short span of time. I recommend using time.sleep(10)
import time
for num in range(len(platform)):
....
....
time.sleep(10)
To check the amount of time required between requests, check the Header under Network in Dev Tools - You should see a retry-after: XXX header.
If you get http status code 429, check the header under Network - You should see a retry-after: XXX header, which basically tells you for how long you should sleep between requests.