Skip to content

Instantly share code, notes, and snippets.

@cnicodeme
Created June 11, 2015 09:17
Show Gist options
  • Save cnicodeme/c14cf19a550b4639e9c0 to your computer and use it in GitHub Desktop.
Save cnicodeme/c14cf19a550b4639e9c0 to your computer and use it in GitHub Desktop.
Twilio quick snippet in Python
# -*- 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