4

I am getting an SSL error using twilio. Anybody have any suggestions?

Error:

Traceback (most recent call last):
  File "communication_easy/that_guy/communicate.py", line 4, in <module>
    from twilio.rest import Client
  File "/usr/local/lib/python2.7/dist-packages/twilio/rest/__init__.py", line 14, in <module>
    from twilio.http.http_client import TwilioHttpClient
  File "/usr/local/lib/python2.7/dist-packages/twilio/http/http_client.py", line 1, in <module>
    from requests import Request, Session, hooks
  File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 84, in <module>
    from urllib3.contrib import pyopenssl
  File "/usr/local/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in <module>
    import OpenSSL.SSL
  File "/usr/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
    from OpenSSL import rand, crypto, SSL
  File "/usr/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 118, in <module>
    SSL_ST_INIT = _lib.SSL_ST_INIT
AttributeError: 'module' object has no attribute 'SSL_ST_INIT'

Code:

import random
from twilio.rest import Client

TWILIO_ACCOUNT_SID = "asdfasdfsdfsdf"
TWILIO_AUTH_TOKEN  = "asdfasdfasdfasf"
TWILIO_NUMBER = "+5555555"


def send_text(body, target_phone_number):
    client = Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
    message = client.messages.create(body=body, from_=TWILIO_NUMBER, to=target_phone_number)

send_text(blah, blah)
0

1 Answer 1

3

According to this github ticket, the problem can be solved by upgrading to pyOpenSSL>=16.2.0

Try:

pip install pyOpenSSL -U
Sign up to request clarification or add additional context in comments.

4 Comments

ty. I did that but it defaulted pip to python3...does using pip default to python3 now if you dont mind?
Which pip depends on the OS and distribution and... Find your python install dir with which python or where python. Use the pip in the scripts directory there.
$ which python /usr/bin/python
That may be the default python from the distribution. I would suggest trying both pip2 and pip3 to see which works for your situation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.