python public 带套接字的 ip(错误:无法分配请求的地址)

python public ip with sockets (err:cannot assign requested addr)

在 python 中允许我的 raspberry pi 访问我的路由器 socketname.bind(96.231.140.202,9999) 的端口 9999 后,出现无法分配错误

为了转发我使用了: myfiosgateway.com/#/firewall/portforward(同方法
适用于我的 apache 服务器)并且我已验证 96.231.140.202 是我的 pub ip

您无法绑定到您的 public IP。您的路由器正在这样做。相反,您想要绑定到您的私有 IP 并将发往 9999 的流量转发到您 pi 上的绑定 IP,该地址将属于符合 rfc 的私有 IP 范围,因此它很可能是 192.168.1.12 或类似的东西.

例如:

socketname.bind(0.0.0.0,9999) #the use of 0.0.0.0 will automatically find your available interface on that raspberry pi.

如果您让我确切知道您使用的是什么套接字库,我可以制作准确的代码。