This route handle three request at a time but upon massive traffic this method fail. Is there any method to handle massive traffic
@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)
CodePudding user response:
Choosing the random from both API responses it's a bad approach. You can randomly choose the URL and fetch the API response from the selected URL.
@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
CodePudding user response:
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)
I rewrite the route,based on your code, maybe need change something.python app.py
start a development server, you need use a production WSGI server instand, like Gunicorn
,you might need know g