RemoteDisconnected: Remote end closed connection without response when using docker

I am writing a python flask app that calls openAI like this

response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
                {"role": "system", "content": command},
                {"role": "user", "content": text}
            ]
        )

When I run my flask app locally in my local environment, the app seems to run without fail. When I dockerize this app and try and run this in the docker environment locally, I get these errors.

RemoteDisconnected: Remote end closed connection without response
ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

The errors persist, even if I try and run it outside docker until the container is deleted. Is there any reason for not being able to run on docker?

dockerfile below

FROM python:3.8-slim-buster
COPY ./ /tmp/
WORKDIR /tmp
RUN pip install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ["python"]
CMD ["run_algo.py"]