Forums

Using Twilio demo

22:26 ~ $ python2 send_sms.py
Traceback (most recent call last):
File "send_sms.py", line 15, in <module>
body="Hello from Python!")
File "/usr/local/lib/python2.7/dist-packages/twilio/rest/resources/messages.py", line 122, in create
return self.create_instance(kwargs)
File "/usr/local/lib/python2.7/dist-packages/twilio/rest/resources/base.py", line 365, in create_instance
data=transform_params(body))
File "/usr/local/lib/python2.7/dist-packages/twilio/rest/resources/base.py", line 200, in request
resp = make_twilio_request(method, uri, auth=self.auth, kwargs)
File "/usr/local/lib/python2.7/dist-packages/twilio/rest/resources/base.py", line 152, in make_twilio_request
resp = make_request(method, uri,
kwargs)
File "/usr/local/lib/python2.7/dist-packages/twilio/rest/resources/base.py", line 117, in make_request
resp, content = http.request(url, method, headers=headers, body=data)
File "/usr/local/lib/python2.7/dist-packages/httplib2/init.py", line 1609, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/usr/local/lib/python2.7/dist-packages/httplib2/init.py", line 1351, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/usr/local/lib/python2.7/dist-packages/httplib2/init.py", line 1272, in _conn_request
conn.connect()
File "/usr/local/lib/python2.7/dist-packages/httplib2/init.py", line 1075, in connect
raise socket.error, msg
socket.error: [Errno 111] Connection refused
22:26 ~ $

Is this a program problem or am I not configured in pythonanywhere? Thanks

After much research, I found we need to setup proxy manually! Ugh... Here is the added code for 2.7

import os
from urlparse import urlparse

from twilio.rest.resources import Connection
from twilio.rest.resources.connection import PROXY_TYPE_HTTP

proxy_url = os.environ.get("http_proxy")
host, port = urlparse(proxy_url).netloc.split(":")
Connection.set_proxy_info(host, int(port), proxy_type=PROXY_TYPE_HTTP)

Hi there, we now have a specific help page on setting up twilio to use the pythonanywhere proxy (for free accounts)