Forums

Error thrown when trying to use Twilio!

When I execute the program locally, it works like a charm. Using it here throws the following error.

Traceback (most recent call last): File "/home/ectobiologist7/desiderius.py", line 77, in <module> asendoff() File "/home/ectobiologist7/desiderius.py", line 73, in asendoff body=billiam, File "/usr/local/lib/python3.4/dist-packages/twilio/rest/resources/messages.py", line 122, in create return self.create_instance(kwargs) File "/usr/local/lib/python3.4/dist-packages/twilio/rest/resources/base.py", line 365, in create_instance data=transform_params(body)) File "/usr/local/lib/python3.4/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/python3.4/dist-packages/twilio/rest/resources/base.py", line 152, in make_twilio_request resp = make_request(method, uri, kwargs) File "/usr/local/lib/python3.4/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/python3.4/dist-packages/httplib2/init.py", line 1314, in request (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey) File "/usr/local/lib/python3.4/dist-packages/httplib2/init.py", line 1064, in _request (response, content) = self._conn_request(conn, request_uri, method, body, headers) File "/usr/local/lib/python3.4/dist-packages/httplib2/init.py", line 987, in _conn_request conn.connect() File "/usr/lib/python3.4/http/client.py", line 1223, in connect super().connect() File "/usr/lib/python3.4/http/client.py", line 834, in connect self.timeout, self.source_address) File "/usr/lib/python3.4/socket.py", line 512, in create_connection raise err File "/usr/lib/python3.4/socket.py", line 503, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused

I've tried what I've seen in other topics -- force changing the proxy and even switching to python 2.7 -- and nothing has worked! It's not an issue with the whitelist either, as all the sites used are approved. Are there any other potential fixes?

You need to set the proxy correctly and use Python 2.7. This code:

from twilio.rest.resources import Connection
from twilio.rest.resources.connection import PROXY_TYPE_HTTP
from twilio.rest import TwilioRestClient
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
Connection.set_proxy_info(
    "proxy.server",
    3128,
    proxy_type=PROXY_TYPE_HTTP
)
print(vars(Connection.proxy_info()))
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
resources = client.calls.list()

works fine in Python 2.7, but not in 3. The issue is described at the end of this forum topic

This worked, thank you! I've never worked with python 2 before so I just did some trial and error and research until everything was proper for python 2.