First a little background. I first started working with the Yun board about 4 years ago because I needed to send text message alerts from a project I was working on. After doing some research I found a website that had all the instructions to update Python and its tools and then install Twilio. Worked great and it was easy to incorporate into my code. A couple of years later, Twilio quit working and I never figured out why, but I thought it was something to do with Python. Many hours of trouble shooting and nothing to show for except frustration. I stopped working on that project.
Fast forward to today, and I'm working on this project again. So the first thing was obviously getting Twilio to work again. So, I started doing research on the subject on the intertube and there was a lot of information about the subject, all of it was of no help. So after getting wrapped around the axle, going from one rabbit hole to another and the frustration level rising to epic levels, I decided to contact Twilio and see if they had a solution. I started an email chain with them and showing the log files for all the failures in the installation of the Python tools and they replied that the Twilio installation was failing because the Python tools was an old version that needed to be updated. They were correct but when I updated tools it said everything was up to date. Oh, Joy! In thinking this whole thing over, I was receiving a lot of caution messages that Python was not going to be supported any more and Python3 was going to take its place. Well isn't that special. A little more investigation and I was still drawing a blank.
As thoroughly urinated as I was, i figured that there must be other people having this same problem, so I decided I would come up with a simple fix for this. And, low and behold, I did.
Some pre requisites, Start by upgrading your Yun to latest openwriter software version. I'm not going into the weeds in all this as I'm sure most of you are familiar with this fire drill. Then add some memory by installing an sd card and running the Arduino code to expand it on the board, again, I think you can find it. Next create a swap file so you don't run out of space when you do the installs. One other thing that I found to be helpful is to increase the space on tmpfs to 300 meg.
Now here is the fun stuff that fixed this. I used the command prompt to login to the board and I sent the following commands:
opkg remove python-pip
opkg remove python-setuptools
opkg remove python
opkg install python3-openssl
opkg install python3-pip
opkg install python3-setuptools
python3-pip install twilio
I then sent my first text message and it worked. I almost wet myself I was so surprised!
Also, the way you write your scripts to send a text has changed and so here is what workes for me.
from twilio.rest import Client
Your Account SID from Twilio Cloud Communications | Web Service API for building Voice and SMS Applications
account_sid = 'xxxxxxxx'
Your Auth Token from Twilio Cloud Communications | Web Service API for building Voice and SMS Applications
auth_token = 'xxxxxxx'
client = Client(account_sid, auth_token)
message = client.messages.create(
to='+1 xxxxxxxxxx' ,
body="Hello from the HomeAutomation Yun! I finally got that sonsabitch")
Ok, boys and girls, there it is. I hope this goes as well for you as it did for me. The only problem going forward is that this works now and that is until some butt hole goes out and changes something in Open Writer or Python that causes it stop working. So much for backward compatibility, but I'm sure that would be too much to ask.