Pass a Requests-based TwilioHttpClient to the Python REST client to configure its proxy route:

from twilio.http.http_client import TwilioHttpClient
from twilio.rest import Client

transport = TwilioHttpClient(
    timeout=30,
    proxy={
        'http': 'http://proxy.example:8080',
        'https': 'http://proxy.example:8080',
    },
)
client = Client(account_sid, auth_token, http_client=transport)

Use the application’s Twilio account_sid and auth_token, then make resource calls through this client instance. Calls made through another default client will use that client’s transport.

Twilio’s API uses HTTPS, so the map needs its https entry. The entry’s HTTP URL describes the proxy listener; the API connection remains HTTPS. An endpoint chosen from the HTTP proxy list belongs in this map, while the Twilio account still authenticates the API operation.

TwilioHttpClient also merges applicable Requests environment settings during transmission. Check the process’s proxy, bypass and trust settings if its route differs from the intended one.

A proxy requiring authentication needs its own account credentials. The Twilio token authenticates API operations.

Mikanda mikatakata