sjmf / bulk-sms

A dead simple bulk SMS client for Twilio (in Python)
47 stars 37 forks source link

Skip Invalid Numbers/ Give list of those invalid numbers atfer aswell #4

Closed KingTut121 closed 3 years ago

KingTut121 commented 3 years ago

Code stops when it comes upon an invalid number

 raise self.exception(method, uri, response, 'Unable to create record')

twilio.base.exceptions.TwilioRestException: HTTP 400 error: Unable to create record: The 'To' number + is not a valid phone number.

sjmf commented 3 years ago

Please try the following changes to the sms.py file:

At the top after the other import statements:

 import TwilioRestException from twilio.base.exceptions

Then change this code on line 50:

        # Send the sms text to the number from the CSV file:
        print("Sending to " + num)
        message = client.messages.create(to=num, from_=from_num, body=sms)

to this:

        # Send the sms text to the number from the CSV file:
        print("Sending to " + num)
        try:
            message = client.messages.create(to=num, from_=from_num, body=sms)
        except TwilioRestException as e:
            print('Failed to send message to {}'.format(num))
            print(e)
            continue

Let me know if it works.

KingTut121 commented 3 years ago

My bad if this is just an simple fix it’s just that I’m new to python lol. I’ve ran into an invalid syntax error here. What should be done?

On Tue, Feb 23, 2021 at 9:02 AM Samantha Finnigan notifications@github.com wrote:

Please try the following changes to the sms.py file:

At the top:

import TwilioRestException from twilio.base.exceptions

Then change this code on line 50 http://sms.py#L50:

    # Send the sms text to the number from the CSV file:
    print("Sending to " + num)
    message = client.messages.create(to=num, from_=from_num, body=sms)

to this:

    # Send the sms text to the number from the CSV file:
    print("Sending to " + num)
    try:
        message = client.messages.create(to=num, from_=from_num, body=sms)
    except TwilioRestException as e:
        continue

Let me know if it works.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sjmf/bulk-sms/issues/4#issuecomment-784223660, or unsubscribe https://github.com/notifications/unsubscribe-auth/AS6WTHEYRZAMJUR4ASDGETTTAOYOLANCNFSM4YCQVXZA .

sjmf commented 3 years ago

I'm trying to understand what the issue is, but I need more information. If there's a syntax error, please look at the error message and try and understand which part of the code it's hitting it on.

For me to be able to help, I need to see the traceback and the code which is throwing the error.

The 'traceback' is the error message, including all the lines which show where it occurs in the program– the bit you removed from the original post. ;)

At a complete guess, given that you're new to Python, have you mixed tabs and spaces in the file?