Raspberry Novice
Posts: 8
Joined: Mon Jan 29, 2018 1:25 am
Location: Florida

twilio import Error with SSL

Mon Jan 29, 2018 2:03 am

Hello fellow Raspberry PI 3 users, I recently was assigned a assignment in my class using the following code:

Code: Select all

#detect_intruder_ldr.py
from gpiozero import LightSensor,Buzzer
from time import sleep
import twilio
import twilio.rest
from twilio.rest import Client

def main():
    ACCOUNT_SID = "AC5545aca088a59032a7dda020858053b4"
    AUTH_TOKEN = "612ef2b663ed8181b907435e3c4859b3"
    ldr = LightSensor(4) # GPIO 4
    buzzer = Buzzer(17) # GPIO17
    message_sent= False
    try:
        while True:
            sleep(0.2)
            print("ldr.value " + str(ldr.value))
            client = Client(ACCOUNT_SID,AUTH_TOKEN)
            to_phone_number = " "# phone
            from_phone_number = " " # twilio phone
            body_message = "Intruder detected!" # message  
            if ldr.value < 0.9:
                print("Light Blocked")
                buzzer.on()
                sleep(3)
                buzzer.off()
                if not message_sent:
                    client.messages.create(to=to_phone_number,
                            from_= from_phone_number,
                            body=body_message)
                message_sent = True
                #break
            else:
              print("No intruder")
    except KeyboardInterrupt:
        print("Exiting...")
    finally:
        ldr.close()
        buzzer.close()
main()
I am using the python 3.4.2 idle and as I run it I get the following error: Import error No Twilio module found. Naturally I go sudo pip 3 install twilio upgrade as referenced on another thread on this forum but its telling me no Twilio package can be downloaded because no SSL/ TLS module is found. Please help. The Twilio version is 6.10.2.
Last edited by Raspberry Novice on Mon Jan 29, 2018 7:16 pm, edited 1 time in total.

Raspberry Novice
Posts: 8
Joined: Mon Jan 29, 2018 1:25 am
Location: Florida

Re: twilio import Error

Mon Jan 29, 2018 5:41 pm

supra wrote:
Mon Jan 29, 2018 3:43 am

Code: Select all

sudo pip3 install twilio
or

Code: Select all

sudo pip3 install twilio --upgrade
Thanks but when I run that in terminal I get this:

Code: Select all

 sudo pip3 install twilio
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting twilio
  Could not fetch URL https://pypi.python.org/simple/twilio/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
  Could not find a version that satisfies the requirement twilio (from versions: )
No matching distribution found for twilio
 

Raspberry Novice
Posts: 8
Joined: Mon Jan 29, 2018 1:25 am
Location: Florida

Re: twilio import Error with SSL

Mon Jan 29, 2018 7:13 pm

I fixed the SSL error by upgrading Python to 3.6.4 but the IDLE still does not recognize the Import Twilio. Rest library client.

Raspberry Novice
Posts: 8
Joined: Mon Jan 29, 2018 1:25 am
Location: Florida

Re: twilio import Error with SSL

Mon Jan 29, 2018 7:20 pm

supra wrote:
Mon Jan 29, 2018 7:17 pm
Raspberry Novice wrote:
Mon Jan 29, 2018 7:13 pm
I fixed the SSL error by upgrading Python to 3.6.4 but the IDLE still does not recognize the Import Twilio. Rest library client.
What's version twilio you have?
6.10.2

Raspberry Novice
Posts: 8
Joined: Mon Jan 29, 2018 1:25 am
Location: Florida

Re: twilio import Error with SSL

Tue Jan 30, 2018 3:09 am

supra wrote:
Mon Jan 29, 2018 7:22 pm
Can you try this link? https://abhrajit.blogspot.ca/2016/05/in ... buntu.html
No output given other than error no command import found.
https://imgur.com/a/dw1cQ

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: twilio import Error with SSL

Wed Jan 31, 2018 12:41 pm

That screenshot shows you typing the import command at a terminal prompt. That's not going to work.

The import command needs to be in a python environment so run "python3" from the terminal prompt and then try your import line.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12398
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: twilio import Error with SSL

Wed Jan 31, 2018 4:53 pm

supra wrote:
Tue Jan 30, 2018 9:15 pm
Raspberry Novice wrote:
Tue Jan 30, 2018 3:09 am
supra wrote:
Mon Jan 29, 2018 7:22 pm
Can you try this link? https://abhrajit.blogspot.ca/2016/05/in ... buntu.html
No output given other than error no command import found.
https://imgur.com/a/dw1cQ
Very sorry, my friend, Only moderator(s) can help or not.
nonsense!

Raspberry Novice
Posts: 8
Joined: Mon Jan 29, 2018 1:25 am
Location: Florida

Re: twilio import Error with SSL

Wed Jan 31, 2018 8:07 pm

elParaguayo wrote:
Wed Jan 31, 2018 12:41 pm
That screenshot shows you typing the import command at a terminal prompt. That's not going to work.

The import command needs to be in a python environment so run "python3" from the terminal prompt and then try your import line.
Thank you for your guidance. Here is what i get as result: https://imgur.com/dqZtQLs.

Also, thank you and Supra for bearing with me , I am a newbie to Python so my apologies for being a nuisance.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: twilio import Error with SSL

Wed Jan 31, 2018 8:22 pm

OK - so we're getting somewhere.

That error says the gpiozero module isn't installed.

At a command terminal, try:

Code: Select all

sudo apt install python3-gpiozero
and then run your code again.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

Raspberry Novice
Posts: 8
Joined: Mon Jan 29, 2018 1:25 am
Location: Florida

Re: twilio import Error with SSL

Thu Feb 01, 2018 12:07 am

Ironically it works on Python 2 but Python 3 doesn't :https://imgur.com/PgTaFSR

Raspberry Novice
Posts: 8
Joined: Mon Jan 29, 2018 1:25 am
Location: Florida

Re: twilio import Error with SSL

Thu Feb 01, 2018 7:04 pm

About elParaguayo's suggestion none of the libraries or imports install correctly when I try to run it on Python 3 using the method described..

@Mahjongg: I noticed viewtopic.php?t=163075 has a similar problem in troubleshooting so if you want me to move the thread to there please let me know?

Return to “Python”