Page 1 of 1

twilio import Error with SSL

Posted: Mon Jan 29, 2018 2:03 am
by Raspberry Novice
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.

Re: twilio import Error

Posted: Mon Jan 29, 2018 5:41 pm
by Raspberry Novice
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
 

Re: twilio import Error with SSL

Posted: Mon Jan 29, 2018 7:13 pm
by Raspberry Novice
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.

Re: twilio import Error with SSL

Posted: Mon Jan 29, 2018 7:20 pm
by Raspberry Novice
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

Re: twilio import Error with SSL

Posted: Tue Jan 30, 2018 3:09 am
by Raspberry Novice
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

Re: twilio import Error with SSL

Posted: Wed Jan 31, 2018 12:41 pm
by elParaguayo
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.

Re: twilio import Error with SSL

Posted: Wed Jan 31, 2018 4:53 pm
by mahjongg
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!

Re: twilio import Error with SSL

Posted: Wed Jan 31, 2018 8:07 pm
by Raspberry Novice
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.

Re: twilio import Error with SSL

Posted: Wed Jan 31, 2018 8:22 pm
by elParaguayo
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.

Re: twilio import Error with SSL

Posted: Thu Feb 01, 2018 12:07 am
by Raspberry Novice
Ironically it works on Python 2 but Python 3 doesn't :https://imgur.com/PgTaFSR

Re: twilio import Error with SSL

Posted: Thu Feb 01, 2018 7:04 pm
by Raspberry Novice
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?