run_PokemonCardSearch.py 643 B

12345678910111213141516171819202122232425262728
  1. import uvicorn
  2. import socket
  3. def get_host_ip():
  4. """
  5. 查询本机ip地址
  6. """
  7. try:
  8. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  9. s.connect(('8.8.8.8', 80))
  10. ip = s.getsockname()[0]
  11. except Exception:
  12. # 如果没有网络,回退到 host name
  13. ip = socket.gethostbyname(socket.gethostname())
  14. finally:
  15. s.close()
  16. return ip
  17. if __name__ == "__main__":
  18. ip = get_host_ip()
  19. port = 18082
  20. print(f" Server running on: http://{ip}:{port}")
  21. print(f" Docs available at: http://{ip}:{port}/docs")
  22. uvicorn.run("app.main:app", host="0.0.0.0", port=port)