HTTPX/requests cannot send REST requests to other service

karlojacmenjakHOBBY

7 months ago

I am trying to get API data from another service I have in the same project.
The code is not changed in a week and it suddenly stopped working today.

The service making the request is a Pycord bot towards FastAPI service

0 Replies

karlojacmenjakHOBBY

7 months ago

ff816097-dff3-4925-9c7d-c91d0c42ee5b


karlojacmenjakHOBBY

7 months ago

Also want to note, using public or private networking seems to not make a difference, I can access the public one via browser but not with the service


7 months ago

can you please define stopped working? that's extremely vague


karlojacmenjakHOBBY

7 months ago

Establishing connection with the httpx/requests to the service fails


karlojacmenjakHOBBY

7 months ago

The end of the log contains this message for httpx:

File "/opt/venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 372, in handle_async_request with map_httpcore_exceptions(): File "/root/.nix-profile/lib/python3.11/contextlib.py", line 158, in __exit__ self.gen.throw(typ, value, traceback) File "/opt/venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 86, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectError: All connection attempts failed [INFO] client: Cleaning up tasks. [INFO] client: Cleaning up after 2 tasks. [INFO] client: All tasks finished cancelling. [INFO] client: Closing the event loop.


karlojacmenjakHOBBY

7 months ago

And this for requests:

File "/opt/venv/lib/python3.11/site-packages/requests/adapters.py", line 700, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='enigmacollective_backend.railway.internal', port=8000): Max retries exceeded with url: /guild_settings/1130063785005174785 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused'))

karlojacmenjakHOBBY

7 months ago

Both services worked, as I printed the url and could see the docs


karlojacmenjakHOBBY

7 months ago

of FastAPI


7 months ago

can you please provide the url in question?



7 months ago

how do you know its listening on port 8000?


karlojacmenjakHOBBY

7 months ago

I use Railway's variables like this: [http://${{enigmacollective_backend.RAILWAY_PRIVATE_DOMAIN}}:${{enigmacollective_backend.PORT](http://${{enigmacollective_backend.RAILWAY_PRIVATE_DOMAIN}}:${{enigmacollective_backend.PORT)}}


7 months ago

that is definitely a good start, but doesn't quite answer my question


karlojacmenjakHOBBY

7 months ago

Are you refering to the settings of the service? In the logs of the deployment the internal port of FastAPI is 8000

You reached the start of the range → Oct 2, 2024 9:12 PM
WARNING:  ASGI app factory detected. Using it, but please consider setting the --factory flag explicitly.
INFO:     Started server process [7]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)

karlojacmenjakHOBBY

7 months ago

but maybe the service settings got messed up?


7 months ago

are you aware that the private network is IPv6 only?


karlojacmenjakHOBBY

7 months ago

yes


7 months ago

you are listening on a IPv4 address


karlojacmenjakHOBBY

7 months ago

ah that's why


karlojacmenjakHOBBY

7 months ago

I need hypercorn


7 months ago

exactly


karlojacmenjakHOBBY

7 months ago

cool, thanks


7 months ago

hypercorn will dual stack bind when you use ::


karlojacmenjakHOBBY

7 months ago

i was experimenting with uvicorn so that's probably a leftover


karlojacmenjakHOBBY

7 months ago

big thanks Brody, you are my hero 😄


7 months ago

no problem!


HTTPX/requests cannot send REST requests to other service - Railway Help Station