我的服务器正在为同一个查询发送多个api请求。这是我的密码:
@SOCKETIO.on('retrieve_bookmarks')
@sleep_and_retry
@limits(calls=5, period=1)
def retrieve_bookmarks(data):
'''This function is for retrieving a
bookmark from the DB'''
print("Inside function")
socket_id = data
pair = ACTIVE_USER_SOCKET_PAIRS[socket_id]
user_id = pair['ID']
event_ids = []
event_details = []
bookmarked_events = DB.session.query(Bookmarks).filter_by(clientId=user_id)
for bookmark in bookmarked_events:
event_ids.append(bookmark.event_id)
redurl = 'https://app.ticketmaster.com/discovery/v2/events/'
for i_d in event_ids:
with RATE_LIMITER:
print("Inside loop")
redurl += i_d
redurl += '.json?apikey={}'.format(APIKEY)
req = requests.get(redurl)
jsontext = req.json()
event_details.append(jsontext)
redurl = 'https://app.ticketmaster.com/discovery/v2/events/'
SOCKETIO.emit('retrieve_bookmarks', event_details, broadcast=False, include_self=True)
如果我在运行我的应用程序时检查控制台,它会显示我为一个id随机收到多个请求的错误。我收到错误的id从不一致。然而,我确实注意到,由于限制为每秒1次呼叫,我从未收到任何违反尖峰逮捕的情况。我的代码有问题吗。速率限制设置为每秒最多5次呼叫。
暂无答案!
目前还没有任何答案,快来回答吧!