我有一个Python3项目,在WSL2/Ubuntu 20上使用
Python服务器:
waitress
进行本地托管。我从VSCode远程启动服务器,但无法使用http://127.0.0.1:5998或http://localhost:5998地址从Windows浏览器连接,出现“无法连接”的错误。我无法找到问题所在,感激任何帮助。Python服务器:
@app.route('/')
def index():
return 'Success'
...
if __name__ == '__main__':
from waitress import serve
process_count = multiprocessing.cpu_count()
serve(app, host="0.0.0.0", port=5998, threads=process_count)
我看到它正在WSL上运行:
> sudo lsof -i -P -n | grep LISTEN
python3 1263 xxx 8u IPv4 39138 0t0 TCP *:5998 (LISTEN)
我也尝试将127.0.0.1作为serve()的ip,而不是0.0.0.0,但没有帮助。
我的Windows防火墙中有一个规则:
> Get-NetFirewallRule -DisplayName WSL
Name : {9c5c5f2b-a9c7-42b7-82ac-f0c2b1819103}
DisplayName : WSL
Description :
DisplayGroup :
Group :
Enabled : True
Profile : Any
Platform : {}
Direction : Inbound
Action : Allow
EdgeTraversalPolicy : Block
LooseSourceMapping : False
LocalOnlyMapping : False
Owner :
PrimaryStatus : OK
Status : The rule was parsed successfully from the store. (65536)
EnforcementStatus : NotApplicable
PolicyStoreSource : PersistentStore
PolicyStoreSourceType : Local
我使用netstat -o
检查了Windows上正在使用的端口,似乎没有任何东西在使用5998端口。