Client can contact server on all ports except 8080

43 views Asked by At

I have a client-server python project. I am using fastapi with uvicorn. When I make a request to the server using the requests library or with postman, I get ConnectionResetError. This only takes place on port 8080 and not any other port I have tried. It was working with port 8080 since I started working on my project a month ago.

I tested with a basic server

from fastapi import FastAPI

# Create an instance of the FastAPI class
app = FastAPI()

# Define a route for the root endpoint "/"
@app.get("/")
async def read_root():
    i = 1
    return {"message": "Hello, world!"}

# Run the FastAPI application using uvicorn server on port 8080
if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8080)

and this client

import requests
response = requests.get(f"http://localhost:8080/")
if response.ok:
    print("No issues")
else:
    print(f"Some issue {response.text}")

This is the error I got:

Exception has occurred: ConnectionError
('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))
ConnectionResetError: \[Errno 54\] Connection reset by peer

During handling of the above exception, another exception occurred:

urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

File "/Users/SP/Documents/VSWorkspace/storage/testing/c1.py", line 2, in \<module\>
response = requests.get(f"http://localhost:8080/")
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))

I checked with lsof -i:8080 to see if anything was running and nothing was. However, I did see this: webfilter 26541 root 25u IPv6 0x5c28b320858b3bef 0t0 TCP localhost:57161->localhost:http-alt (CLOSED) Please let me know if information is missing and I'll add it. Thanks for your help.

0

There are 0 answers