这个问题涉及到Python的Requests模块。
我正在使用requests.get(),但遇到了一个问题:我超过了我要联系的服务器允许的请求速率限制。我在每个requests.get()后设置了time.sleep(),时间是数量级更大的数值。代码如下:
我正在使用requests.get(),但遇到了一个问题:我超过了我要联系的服务器允许的请求速率限制。我在每个requests.get()后设置了time.sleep(),时间是数量级更大的数值。代码如下:
for url in url_list:
success = False
response = requests.get(url)
while not success:
time.sleep(1/250)
if str(response) == "<Response [200]>":
time.sleep(1/250) # Wait Xs between API call
do_stuff(response.text)
success = True
else:
print(response)
print(response.headers)
time.sleep(3)
response = requests.get(url)
我在这里不断地增加我的速率,达到了每秒300个请求,但最多只应该发送每秒125个请求。Requests是否没有暂停脚本直到响应到达?我不确定。我该如何确保不会发送超过我的速率的请求?
time.sleep(0)
。尝试使用1./250
。 - beezz