[Python] Error in Sending Automated SMS with Dialpad and CVS File

Discussão em 'Python' iniciado por Stack, Dezembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    I'm using python to send automated sms messages via Dialpad using the contacts I have in my CVS file (it's formatted as NAME, PHONENUMBER).

    However I keep getting this error - example names and numbers used here:

    Error sending SMS to Bob (+16124855917): b'Not Found'
    Error sending SMS to Larry (+17699643423): b'Not Found'
    Error sending SMS to Harry (+12538355287): b'Not Found'
    Error sending SMS to Barry (+16128562388): b'Not Found'
    Error sending SMS to Gary (+12129748516): b'Not Found'



    The python code:

    import csv
    import requests

    DIALPAD_API_KEY = 'MY-API-KEY'
    DIALPAD_PHONE_NUMBER = 'MY-PHONE-NUMBER'

    def send_sms_message(name, phone_number):
    if not phone_number.startswith('+'):
    phone_number = f'+1{phone_number}'
    url = 'https://dialpad.com/api/v2/sms_messages'
    headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {DIALPAD_API_KEY}'
    }
    data = {
    'from_number': DIALPAD_PHONE_NUMBER,
    'to_number': phone_number,
    'text': f'Is this {name}? I want to make sure I have the right number.'
    }
    response = requests.post(url, headers=headers, json=data)
    if response.status_code == 200:
    print(f'SMS sent to {name} ({phone_number}) successfully')
    else:
    print(f'Error sending SMS to {name} ({phone_number}): {response.content}')
    return response.status_code

    with open('recipients.csv', 'r') as f:
    reader = csv.reader(f)
    for row in reader:
    name = row[0]
    phone_number = row[1].replace(' ', '') # Remove any whitespace
    send_sms_message(name, phone_number)


    I expected the message to be sent to each phone number with their names.

    How can I solve the issue?

    Continue reading...

Compartilhe esta Página