Has anyone had success using Twilio with Micropython on an 8266? I've tested the below in pyton3 and can get it to successfully send a text message. However, when I port it over to micropython (below), the message fails. I went back to the urequests library, which is where I'm getting the failure, and saw that its failing because its passing the data as a dictionary (it fails on row 79). I tried changing it to pass as a string, but then it seems the data isn't sent to Twilio.
Python3 Implementation
import requests
account_sid = "sid"
auth_token = "token"
url = "https://api.twilio.com/2010-04-01/Accounts/" + account_sid + "/Messages.json"
data = {'From': '+18005551234', 'To': '+18005551234', 'Body': 'Text Message'}
try:
resp = requests.post(url=url, data=data, auth=requests.auth.HTTPBasicAuth(account_sid, auth_token))
print(resp.status_code)
except Exception as exc:
print("\nException occured.")
sys.print_exceptin(exc)
Micropython Implementation
import urequests
import ubinascii
account_sid = "sid"
auth_token = "token"
url = "https://api.twilio.com/2010-04-01/Accounts/" + account_sid + "/Messages.json"
data = {'From': '+18005551234', 'To': '+18005551234', 'Body': 'Text Message'}
login = ubinascii.b2a_base64(account_sid.encode('utf8') + b':' + auth_token.encode('utf8'))
headers = {'Authorization': b'Basic ' + login, 'Content-Type': 'application/x-www-form-urlencoded', 'WWW - Authenticate': 'Basic realm = "Twilio API'}
try:
resp = urequests.post(url=url, data=data, headers=headers)
print(resp.status_code)
except Exception as exc:
print("\nException occured.")
sys.print_exceptin(exc)
EDIT: So it seems that its been answered here: Sending SMS in twilio returns 21603 : A 'From' number is required, but even modifying my data, I can't get the message to actually transmit. I've modified the data field to be "To=%2B18005551234&From=%2B18005551234&Body=Test", but that seems to fail as well.