我已經做了一個使用api請求某些數據的python代碼,但api只允許每分鐘發送20個請求。我正在使用urllib來請求數據。另外我使用一個for循環,因爲數據位於一個文件:Python:每分鐘只需要請求20次
for i in hashfile:
hash = i
url1 = "https://hashes.org/api.php?act=REQUEST&key="+key+"&hash="+hash
print(url1)
response = urllib.request.urlopen(url2).read()
strr = str(response)
if "plain" in strr:
parsed_json = json.loads(response.decode("UTF-8"))
print(parsed_json['739c5b1cd5681e668f689aa66bcc254c']['plain'])
writehash = i+parsed_json
hashfile.write(writehash + "\n")
elif "INVALID HASH" in strr:
print("You have entered an invalid hash.")
elif "NOT FOUND" in strr:
print("The hash is not found.")
elif "LIMIT REACHED" in strr:
print("You have reached the max requests per minute, please try again in one minute.")
elif "INVALID KEY!" in strr:
print("You have entered a wrong key!")
else:
print("You have entered a wrong input!")
有沒有辦法讓它只是做每分鐘20個請求?或者如果這是不可能的,我可以讓它在20次嘗試後超時? (順便說一句,它只是代碼的一部分)