how to implement random choice
Question:
how to implement random choice on both url? I had tired when send request i get response from both api not from any one
@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 %20{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 %20{value}&instance_id=api2&access_token=api2'
r = requests.get(api1_url).text
t = requests.get(api_url).text
t1=(r,t)
item=random.choice(t1)
return item
Answers:
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 %20{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 %20{value}&instance_id=api2&access_token=api2'
url = random.choice([api_url, api1_url])
return requests.get(url).text
how to implement random choice on both url? I had tired when send request i get response from both api not from any one
@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 %20{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 %20{value}&instance_id=api2&access_token=api2'
r = requests.get(api1_url).text
t = requests.get(api_url).text
t1=(r,t)
item=random.choice(t1)
return item
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 %20{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 %20{value}&instance_id=api2&access_token=api2'
url = random.choice([api_url, api1_url])
return requests.get(url).text