无法向 twilio pythonanywhere 提供代理信息

Failed to provide proxy info to twilio pythonanywhere

我正在尝试在 pythonanywhere 中使用 Twilio,我知道我需要一个代理才能让它工作。我的代码如下所示:

    class ProxiedTwilioHttpClient(HttpClient):
        """
        General purpose HTTP Client for interacting with the Twilio API
        """
        def request(self, method, url, params=None, data=None, headers=None, auth=None, timeout=None,
                    allow_redirects=False):
        session = Session()
        session.verify = get_cert_file()
        session.proxies = {
                              "https" : "https://52.14.161.178:3128"
                          }

        request = Request(method.upper(), url, params=params, data=data, headers=headers, auth=auth)

        prepped_request = session.prepare_request(request)
        response = session.send(
            prepped_request,
            allow_redirects=allow_redirects,
            timeout=timeout,
        )

        return Response(int(response.status_code), response.content.decode('utf-8'))

def send_sms(phone, content):
    client = Client(api_key, api_secret, account_sid, http_client=ProxiedTwilioHttpClient())
    message = client.messages.create(
        to=phone,
        from_="+19999999999", #of course I use the correct one
        body=content)
    return(message.sid)

但随后returns出现以下错误:

.virtualenvs/sms/local/lib/python2.7/site-packages/requests/‌​adapters.py",
line 502, in send raise ProxyError(e, request=request) requests.exceptions.ProxyError:
HTTPSConnectionPool(host='api.twilio.com', port=443):
Max retries exceeded with url: /2010-04-01/Accounts/XXXXXXXXX/Messages.json (Caused by ProxyError('Cannot connect to proxy.',
NewConnectionError('<urllib3.connection.Verif iedHTTPSConnection object at 0x7fa41a55e090>:
Failed to establish a new connection: [Errno 111] Connection refused',)))

我正在使用以下似乎对其他人有用的答案:

我该如何解决?

您指定您的代码应在 https://52.14.161.178:3128 使用代理。这在 PythonAnywhere 上不起作用,您需要使用该服务提供的代理。要找出用于该地址的地址,请启动 Bash 控制台和 运行

echo $http_proxy

[2018 edit] 我们现在在 getting twilio to work with the pythonanywhere proxy

上有一个特定的页面