此路由一次處理三個請求,但在大量流量時此方法失敗。有什么方法可以處理大量流量
@app.route('/v1.1/userRegistor', methods=['POST', 'GET'])
def job():
count = 0
data = request.get_json()
numbers = data['number']
if count == 0:
api_url = f'https://app.simplywhatsapp.com/api/send.php?number={numbers}&type=text&message=Your OTP is {valuepi1}&instance_id=instance1&access_token=access_token1'
r = requests.get(api_url).text
count = 1
return str(count)
if count == 1:
api1_url = f'https://app.simplywhatsapp.com/api/send.php?number={numbers}&type=text&message=Your OTP is {value}&instance_id=instance2&access_token=access_token2'
r = requests.get(api1_url).text
count = 1
return str(count)
if count == 2:
api2_url = f'https://app.simplywhatsapp.com/api/send.php?number={numbers}&type=text&message=Your OTP is {value}&instance_id=instance3&access_token=access_token3'
r = requests.get(api2_url).text
count = 0
return str(count)
uj5u.com熱心網友回復:
從兩個 API 回應中選擇亂數是一種不好的方法。您可以隨機選擇 URL 并從所選 URL 中獲取 API 回應。
@app.route('/v1.1/userRegistor', methods=['POST','GET'])
def job():
data = request.get_json()
numbers=data['number']
api_url =f'https://app.simplywhatsapp.com/api/send.php?number={numbers}&type=text&message=Your OTP is {value}&instance_id=api1&access_token=api1'
api1_url=f'https://app.simplywhatsapp.com/api/send.php?number={numbers}&type=text&message=Your OTP is {value}&instance_id=api2&access_token=api2'
url = random.choice([api_url, api1_url])
return requests.get(url).text
uj5u.com熱心網友回復:
count = 0
@app.route('/v1.1/userRegistor', methods=['POST', 'GET'])
def job():
global count
data = request.get_json()
numbers = data.get('number')
count_map = {
0: f'https://app.simplywhatsapp.com/api/send.php?number={numbers}&type=text&message=Your OTP is {valuepi1}&instance_id=instance1&access_token=access_token1',
1: f'https://app.simplywhatsapp.com/api/send.php?number={numbers}&type=text&message=Your OTP is {value}&instance_id=instance2&access_token=access_token2'
2: f'https://app.simplywhatsapp.com/api/send.php?number={numbers}&type=text&message=Your OTP is {value}&instance_id=instance3&access_token=access_token3'
}
r = requests.get(count_map[count]).text
count = 1
return str(count)
我根據您的代碼重寫了路線,可能需要更改一些內容。python app.py啟動開發服務器,您需要使用生產 WSGI 服務器實體,例如Gunicorn,您可能需要知道g
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/526741.html
標籤:Python烧瓶
上一篇:燒瓶顯示上傳的CSV檔案的形狀
