无法将 ip 绑定到 AWS 上的 python 套接字

发布于 2025-01-20 04:46:54 字数 449 浏览 0 评论 0原文

我正在 AWS EC2 上使用套接字运行一个简单的 python 脚本。 绑定公共 IP 时,我收到一条错误消息,告诉我无法分配请求的地址。当使用私有 IP 时(只是为了确定而尝试)我没有收到错误,但也无法连接。在 AWS EC2 上运行脚本时应该使用哪个 IP?

# Open socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(("<public ip>", 5000))
# Error when running the script
server_socket.bind(("<public_ip>", 5000))
OSError: [Errno 99] Cannot assign requested address

I am running a simple python script with sockets on AWS EC2.
When binding the public ip I get an error telling me I cannot assign the requested address. And when using the private ip (tried it just to be sure) I don't get an error but can't connect either. Which ip am I supposed to use when running my script on AWS EC2?

# Open socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(("<public ip>", 5000))
# Error when running the script
server_socket.bind(("<public_ip>", 5000))
OSError: [Errno 99] Cannot assign requested address

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文