Windows 11,localhost / 127.0.0.1 呼叫時連接埠號碼發生變化

Windows 11,localhost / 127.0.0.1 呼叫時連接埠號碼發生變化

我正在 Windows 11 上測試在 127.0.0.1:8000 上執行的 fastapi http 伺服器。在另一個終端機中,請求發送到 127.0.0.1:8000 上的伺服器。結果是一個錯誤請求,伺服器說它發生在 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

我已進行網路重置並執行了通常的網路重置操作,但沒有運氣。有誰知道為什麼會發生這種情況以及解決方案是什麼?

相關內容