Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client.messages.create_async hanging in FastAPI #731

Open
mike-guaranteed opened this issue Nov 6, 2023 · 2 comments
Open

client.messages.create_async hanging in FastAPI #731

mike-guaranteed opened this issue Nov 6, 2023 · 2 comments
Labels
status: waiting for feedback waiting for feedback from the submitter

Comments

@mike-guaranteed
Copy link

Issue Summary

A summary of the issue and the environment in which it occurs. If suitable, include the steps required to reproduce the bug. Please feel free to include screenshots, screencasts, or code examples.

Steps to Reproduce

  1. Create a FastAPI app
  2. Create an async route that creates a Client with an AsyncTwilioHttpClient
  3. call await client.messages.create_async()
  4. The future never resolves

Code Snippet

from fastapi import FastAPI

app = FastAPI()

@app.post("/test")
async def test():
    account_sid = os.getenv('TWILIO_ACCOUNT_SID')
    auth_token = os.getenv('TWILIO_AUTH_TOKEN')
    messaging_service_sid = os.getenv('TWILIO_MESSAGING_SERVICE_SID')

    client = Client(account_sid, auth_token, http_client=AsyncTwilioHttpClient())
    message = await client.messages.create_async(    ### never resolves
        messaging_service_sid=messaging_service_sid,
        body='message_content',
        # from_=twilio_number,
        to=phone_number,
    )

If I run create_async like this it works:

async def main():
    account_sid = os.getenv('TWILIO_ACCOUNT_SID')
    auth_token = os.getenv('TWILIO_AUTH_TOKEN')
    messaging_service_sid = os.getenv('TWILIO_MESSAGING_SERVICE_SID')

    client = Client(account_sid, auth_token, http_client=AsyncTwilioHttpClient())
    message = await client.messages.create_async(
        messaging_service_sid=messaging_service_sid,
        body='message_content',
        # from_=twilio_number,
        to=phone_number,
    )

asyncio.run(main())

I have also tried using the regular HTTP client in a non-async path definition, but that also hangs.

Exception/Log

# paste exception/log here

None, the future never resolves

Technical details:

  • twilio-python version: 8.10.1
  • python version: 3.11
@mike-guaranteed
Copy link
Author

I looked into it a bit more, and it seems we were using uvloop in uvicorn because it was available. If I switch uvicorn to useasyncio it still doesn't work. If I use hypercorn with the standard config (asyncio) this code functions fine. If I use hypercorn with uvloop this code does not work. Since it appears the twilio library is not compatible with uvloop, which is fine with us, I can't quite figure out why it won't work in uvicorn with the asyncio event loop, has this behavior been seen before? Our version of uvicorn is 0.23.2.

@tiwarishubham635
Copy link
Contributor

Hi @mike-guaranteed! I would require more context regarding how you are using uvicorn. We can look into this. Thanks!

@tiwarishubham635 tiwarishubham635 added the status: waiting for feedback waiting for feedback from the submitter label Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for feedback waiting for feedback from the submitter
Projects
None yet
Development

No branches or pull requests

2 participants