I'm building a website using Django (not sure if this is relevant) and Python, which allows players of a video game to get their game-histories. This involves pulling information from the API for the game, using a function like this below, where "url" is the url endpoint for the API:
def API_Call(url):
#dictionary to hold extra headers
HEADERS = {"X-API-Key":'myapikey'}
#make request
try:
r = requests.get(url, headers=HEADERS, timeout=5)
return r.json()
except request.exceptions.RequestException as e:
return {"ErrorCode":"Generic Request Exception"}
except request.exceptions.HTTPError as e:
return {"ErrorCode": "HTTPError"}
except request.exceptions.Timeout as e:
return {"ErrorCode": "Timeout"}
The API I call has rate limits imposed (something like 200/10 minutes from a single IP address), and I was hoping for some direction or help in understanding how this will work. That is, if I have 10 users log onto the website at the same time, and try to pull histories, will the API view all requests as coming from the same IP address? Or will it see it coming from 10 different IP addresses? If the former, is there a way to have the user's computer do the requests?
Sorry if the above question is too vague; if other specific information would help please let me know. I'm very new to website-building, and I'm really just hacking it so far, figuring out piece by piece what I need to accomplish various goals. I'm also still in a very basic testing mode, and have not completely figured out where/how to actually launch the website (if that matters).
答案 0 :(得分:1)
If your webserver makes calls to the game API, then the server running the API will see all those request as coming from one IP address, being the address of your server. It doesn't matter whether those requests were performed in a cron job or by requests from a dozen different users, since it is always your server that communicates to the game servers.
There is a way to make a user's computer do the request, but then it will become a bit hacky. You either have to use an AJAX request, but that will only work if the server API responds with the right headers that allow cross domain AJAX calls. Or you'll have to hack something together using iframes or fake images, but then things will become ugly quite quickly.