无法向twilio pythonanywhere提供代理信息

时间:2017-06-04 06:39:26

标签: python twilio pythonanywhere

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

import React, { Component } from 'react';
import { AppRegistry } from 'react-native';

import Root from './src/containers/Root';
import configureStore from './configureStore';

export default class CounterReactNativeRedux extends Component {
  render() {
    return (<Root store={configureStore()} />)
  }
}

AppRegistry.registerComponent('CounterReactNativeRedux', () => CounterReactNativeRedux);

但是它会返回以下错误:

    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)

我使用的答案似乎适用于其他人:https://stackoverflow.com/a/43608637/7298530

我该如何解决?

1 个答案:

答案 0 :(得分:2)

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

echo $http_proxy

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

上有一个特定页面