Windows 11、localhost / 127.0.0.1 のポート番号が呼び出し時に変更される

Windows 11、localhost / 127.0.0.1 のポート番号が呼び出し時に変更される

127.0.0.1:8000 で実行されている Windows 11 で fastapi http サーバーをテストしています。別のターミナルで、127.0.0.1:8000 のサーバーにリクエストが送信されます。結果は Bad Request で、サーバーは 127.0.0.1:50340 で発生したと報告します。ポート番号は 8000 から 50340 に変更されました。クエリを再度実行すると、ポートが別の番号に再度変更されます。詳細は出力に示されています。

サーバー出力は次のとおりです。

INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [2368] using StatReload
{"event":"logger initialized","level":"info","timestamp":"2023-02-17T14:53:00.373918"}
{"event":"logger initialized","level":"info","timestamp":"2023-02-17T14:53:00.592613"}
INFO:     Started server process [24260]
INFO:     Waiting for application startup.
INFO:     Application startup complete.

クライアントの出力は次のとおりです。

DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): 127.0.0.1:8000
send: b'POST /api/query HTTP/1.1\r\nHost: 127.0.0.1:8000\r\nUser-Agent: python-requests/2.28.2\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Length: 160\r\nContent-Type: application/json\r\n\r\n'
send: b'{"request_type": "query", "query_items": ["196313", "9223372032559872706", "262946", "9223372032559842189"], "number_of_predictions": 10, "include_score": true}'
reply: 'HTTP/1.1 404 Not Found\r\n'
header: date: Fri, 17 Feb 2023 14:54:23 GMT
header: server: uvicorn
header: content-length: 76
header: content-type: application/problem+json
DEBUG:urllib3.connectionpool:http://127.0.0.1:8000 "POST /api/query HTTP/1.1" 404 76

クライアント要求後のサーバー出力は次のとおりです。

INFO:     127.0.0.1:50340 - "POST /api/query HTTP/1.1" 404 Not Found

テスト127.0.0.1:8000は動作

PS C:\Windows\System32> Test-NetConnection 127.0.0.1 -p 8000
ComputerName     : 127.0.0.1
RemoteAddress    : 127.0.0.1
RemotePort       : 8000
InterfaceAlias   : Loopback Pseudo-Interface 1
SourceAddress    : 127.0.0.1
TcpTestSucceeded : True

ネットワークをリセットし、通常のネットワーク リセット操作を実行しましたが、うまくいきませんでした。なぜこのようなことが起こるのか、また解決策は何なのかを知っている人はいますか?

関連情報