Got Warning In Flask API while hitting OpenAI ChatGPT API: "Resource Warning: Unclosed ssl.SSLSocket

So i’ve been doing some works to build a REST API with Flask including an API to hit OpenAI ChatGPT Completion API to generate a response for Chatbot use-case.

Whenever my API received a request from client/users. This Warning always raised in the log:

[13/Apr/2023 10:30:42] "POST /chatbot HTTP/1.1" 200 -
sys:1: ResourceWarning: unclosed <ssl.SSLSocket fd=10, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.4.210', 39590), raddr=('104.18.6.192', 443)>

Does anyone have experienced the same thing? or is this normal, something that we can ignore? I would be really grateful if someone actually had an idea of how to handle this kind of warning and perhaps share the solution

Thank you in advance

I’m having the same issue, specifically when I run PyTest. It’s the same remote IP address too, and that IP address is definitely OpenAI’s, so this is definitely an issue with OpenAI. I’m using the embedding model, so I don’t think it’s specific to the completions API.

Hi and welcome to the developer forum!

OpenAI already has a complete python library to handle these events, the work of debugging connection issues had already been done, if you wish to do it as a technical exercise, that’s great, but you should know you don’t have to. Just import OpenAI after pip3 install openai

I can’t speak to the original poster, but I have been using the openai library, not a pure REST API, so I believe this is still an issue.

You’re getting the unclosed resource warning or something else?

That’s correct - I’m getting pretty much the identical warning as the original poster, though I am using the openai Python SDK for embeddings. I only get the warning, however, when I’m running unit tests with PyTest.

I’m getting same warning when running concurrently inside a concurrent.futures.ThreadPoolExecutor.

Same error, though the error comes from flask_oidc

flask_oidc/init.py:892

As a general note on this, it is not an “error” it is a warning that concurrent connections are open, this can happen as part of normal usage.