【问题标题】:OSError: [Errno 99] error while attempting to bind on address cannot assign requested addressOSError: [Errno 99] 尝试绑定地址时出错,无法分配请求的地址
【发布时间】:2020-06-06 21:02:21
【问题描述】:

我在阿里巴巴免费弹性 IP 中运行代码时收到此消息:

OSError: [Errno 99] error while attempting to bind on address ('147.139.5.81', 31333): cannot assign requested address

这是在 Amazon EC2 中正确运行的代码:'

ip = '147.139.5.81' #In Amazon EC2, ip will be different

    start_server = websockets.serve(
        hello, ip, 31333
    )

    asyncio.get_event_loop().run_until_complete(start_server)
    asyncio.get_event_loop().run_forever()

ifconfig -a shows:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.31.173.211  netmask 255.255.240.0  broadcast 172.31.175.255
        ether 00:16:3e:01:30:8e  txqueuelen 1000  (Ethernet)
        RX packets 473419  bytes 267646492 (267.6 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 309017  bytes 92824868 (92.8 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 72620  bytes 4035134 (4.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 72620  bytes 4035134 (4.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

%dig +short myip.opendns.com @resolver1.opendns.com 显示:

147.139.5.81

可能是什么问题?我已经使用 ip: 147.139.5.81 sshed 到这个 VPS

【问题讨论】:

    标签: python-3.x alibaba-cloud


    【解决方案1】:

    您必须使用 VPC 网络类型的 ECS 实例,因为您的 ECS 实例的 inet 是私有 IP。对于 VPC 网络类型的 ECS 实例,ECS 实例的公网 IP 在 OS 内部是不可见的,因此您无法绑定它。

    您可以绑定 0.0.0.0 并使用 ECS 实例的安全组来允许/阻止流向 ECS 的流量。

    【讨论】:

    • 有什么方法可以使实例的公共 IP 对操作系统可见?
    【解决方案2】:

    我有 VPS 不是亚马逊。 ip = '0.0.0.0' 它对我有用

    【讨论】:

      猜你喜欢
      • 2023-03-11
      • 2018-04-27
      • 2021-05-26
      • 2020-09-04
      • 1970-01-01
      • 1970-01-01
      • 2017-09-13
      • 1970-01-01
      • 2017-05-08
      相关资源
      最近更新 更多