twilio / twilio/twilio-python

class AsyncTwilioHttpClient takes "proxy_url" parameter, but does not use it for anything.

Open
#788 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority: medium status: work in progress type: bug
Dominant language
Python
Stars
2.1k
Forks
815
Avg merge
2d 13h
Merged PRs (30d)
2

Description

Issue Summary

I work behind a firewall and use a proxy to make requests. I wanted to send messages asynchronously using twilio and followed the steps here in the documentation to make asynchronous message sending requests. I used the "proxy_url" parameter of the AsyncTwilioHttpClient class to specify my proxy url string in the form "http://xxx.xxx.xxx.xxx:xxxx". It did not work and i got an error saying "cannot connect to host api.twilio.com 443".

My first assumptions were that maybe the proxy url string format I had used was wrong, or maybe it is a proxy/firewall issue on our end.
I was able to send synchronous messages just fine using the proxy, so that was not the issue. Then I looked at the code for AsyncTwilioHttpClient and found that while it is taking the proxy string, It is not actually doing anything with it. You may confirm the same here at the github page for the code.

Am I doing something wrong here? Am I missing something?
Am I supposed to use a different way to specify the proxy to use for AsyncTwilioHttpClient?

Code Snippet for asynchronous messaging (gives error):
from twilio.http.async_http_client import AsyncTwilioHttpClient
from twilio.rest import Client

async def main():
    account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    auth_token  = "your_auth_token"
    http_client = AsyncTwilioHttpClient(proxy_url= "http://xxx.xxx.xxx.xxx:xxxx")
    client = Client(account_sid, auth_token, http_client=http_client)

    message = await client.messages.create_async(to="+1xxxxxxxxxx", from_="+1xxxxxxxxxx",
                                                 body="Hello there!")

    print(message.sid)

asyncio.run(main())

Code Snippet for synchronous messaging (does not give error):
from twilio.http.http_client import TwilioHttpClient
from twilio.rest import Client

def main():
    account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    auth_token  = "your_auth_token"
    http_client = TwilioHttpClient(proxy= {"http" : "http://xxx.xxx.xxx.xxx:xxxx"})
    client = Client(account_sid, auth_token, http_client=http_client)

    message = client.messages.create(to="+1xxxxxxxxxx", from_="+1xxxxxxxxxx",
                                                 body="Hello there!")
    print(message.sid)

main()
Exception/Log

twilio_error

Technical details:
  • twilio-python version: 9.0.0
  • python version: 3.10

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with twilio/http/async_http_client.py at the referenced constructor and trace how asynchronous requests are issued. Compare its proxy handling with twilio/http/http_client.py and verify that the supplied proxy_url is used for asynchronous requests through the example. Done means the asynchronous client can connect through the configured proxy.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.