Skip to content

Instantly share code, notes, and snippets.

@caseydm
Last active February 16, 2023 21:55
Show Gist options
  • Save caseydm/80b6e3f5961f683bb8edb8636c098579 to your computer and use it in GitHub Desktop.
Save caseydm/80b6e3f5961f683bb8edb8636c098579 to your computer and use it in GitHub Desktop.
import grequests
def test_rate_limit_no_key():
# test url 20 times at once
# 10 of the responses are 429, rate limited
urls = []
for i in range(20):
urls.append(
"https://api.openalex.org/works?filter=doi:10.1016/j.jfca.2023.105165")
rs = (grequests.get(u) for u in urls)
print(grequests.map(rs))
def test_rate_limit_with_key():
# test 101 times at once
# 1 response is 429, rate limited
urls = []
for i in range(101):
urls.append("https://api.openalex.org/works?filter=doi:10.1016/j.jfca.2023.105165&api_key=my_api_key")
rs = (grequests.get(u) for u in urls)
print(grequests.map(rs))
if __name__ == "__main__":
print("no key")
test_rate_limit_no_key()
print("with key")
test_rate_limit_with_key()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment