Created
June 11, 2015 09:17
-
-
Save cnicodeme/c14cf19a550b4639e9c0 to your computer and use it in GitHub Desktop.
Twilio quick snippet in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
from flask import current_app | |
from urllib import urlencode | |
import httplib2 | |
def twilio(phone, message): | |
params = { | |
'From': current_app.config['TWILIO_FROM'], | |
'To' : phone, | |
'Body': message | |
} | |
h = httplib2.Http(timeout=3, disable_ssl_certificate_validation=True) | |
h.add_credentials(current_app.config['TWILIO_AUTH_KEY'], current_app.config['TWILIO_AUTH_TOKEN']) | |
try: | |
h.request(current_app.config['TWILIO_URL'], 'POST', urlencode(params), headers={'Content-type': 'application/x-www-form-urlencoded'}) | |
return response | |
except socket.error: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment