Jan 15, 2021 2 mins

ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:2633)

Learn Python Learn Python

I'm getting ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:2633) error while executing API request parallel using HTTPX async. Here is my code.

async with httpx.AsyncClient() as client:

    await get_token(client)

    get_query = "SELECT customer_id, inventory_id FROM Account;"

    res = cursor.fetchall()
    print("Account query executed")

    for acc in res:
        cus_id = acc[0]
        inv_id = acc[1]

        if cus_id == None or inv_id == None:
            print("Skip record")
            await get_inventory(client, acc[0], acc[1])

Why is This Error?

The error “ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:2633)” in Python typically occurs when there is a non-blocking SSL/TLS socket operation, and the underlying SSL/TLS library signals that it wants to perform a read operation, but the data is not currently available.

Here’s a breakdown of the key components of the error message

ssl.SSLWantReadError: This is a specific exception in the ssl module of Python, indicating that the SSL/TLS library wants to perform a read operation.

The operation did not complete (read): Specifies that the read operation being attempted did not complete successfully.

  • (_ssl.c:2633): Provides additional information about the location in the C code where the error occurred. This information is less relevant for general troubleshooting and more for debugging purposes.

To address this error, consider the following steps

Check Socket Blocking Mode: If you are working with a socket, ensure that it is set to non-blocking mode if your application relies on non-blocking I/O operations.

Handle WantReadError: If you are using non-blocking I/O and handling SSL/TLS sockets directly, make sure your code is prepared to handle SSLWantReadError exceptions. You might need to implement proper error handling and retry mechanisms when this exception occurs.

Verify Network Connection: Ensure that the network connection is stable and that there are no issues with the connectivity between the client and server.

Check SSL/TLS Versions: Verify that both the client and server are using compatible versions of the SSL/TLS protocol. Mismatched versions can lead to unexpected errors.

Review SSL/TLS Configuration: If you have control over the SSL/TLS configuration, check whether the settings and parameters are correctly configured on both the client and server sides.

Inspect Code Logic: Review the logic of your code that interacts with SSL/TLS sockets. Ensure that your code correctly handles non-blocking I/O scenarios and is resilient to potential errors.

Update Python and Libraries: Ensure that you are using an up-to-date version of Python and any relevant libraries (e.g., ssl, requests, or others) to benefit from bug fixes and improvements.

By carefully inspecting your code, handling SSLWantReadError appropriately, and ensuring proper network and SSL/TLS configurations, you can address th “ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:2633)” error in your Python application.


  • Avatar

    Danielle Carline

    Posted on

    I solved this error by adding Verify=False in AsyncClient like this.


Write a comment

You can use the Markdown syntax to format your comment.

  • Tags:
  • python
  • Share: