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
Asked By: Mubeenuddin Abbasi

||

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
Answered By: Rahul K P
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.