【问题标题】:OSError: [WinError 10049] The requested address is not valid in its contextOSError: [WinError 10049] 请求的地址在其上下文中无效
【发布时间】:2017-11-20 06:45:22
【问题描述】:

当我运行代码时:

name = socket.gethostname()

#ip = socket.gethostbyname(name)
port = 5000

ip = "90.95.52.220"
print("Ip server: %s"%ip)

s.bind((ip, port)

我得到这个错误:

“OSError: [WinError 10049] 请求的地址在其上下文中无效”

如果我使用 socket.gethostbyname(name) 获取 IP,它会给我一个 IP,但是通过使用该 IP,其他人无法连​​接到我的服务器。我能做些什么?我阅读了类似问题的答案,但没有一个有效。

【问题讨论】:

    标签: python-3.x sockets


    【解决方案1】:

    您的系统可能有许多分配给它的 IP 地址。在 Windows 中,您可以通过 ipconfig /all 命令查看。但是只有一个IP地址是外部的。您需要绑定到该 IP 地址,以便您的朋友连接到您。如果您的系统是通过 wifi 连接的,那么它将是您的 wifi 适配器 ip 地址。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 2020-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多