套接字错误“IP 地址在其上下文中无效” - Python
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4657347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Socket error "IP address not valid in its context" - Python
提问by RadiantHex
I'm using Python 2.6and Windows Server 2008.
我正在使用Python 2.6和Windows Server 2008。
The server has two IP addresses 1 internal, 1 external.
服务器有两个 IP 地址 1 internal, 1 external。
I need Python to use the external IP address, but while doing so I get this:
我需要 Python 来使用外部 IP 地址,但是这样做时我得到了这个:
socket.error: [Error 10049] The requested address is not valid in its context
socket.error: [Error 10049] 请求的地址在其上下文中无效
To be more precise I'm using Django's runserver command for who is familiar with it
更准确地说,我正在为熟悉它的人使用 Django 的 runserver 命令
Edit:
编辑:
ipconfigonly brings up the internal IP address, while all services I have running are using the external IP without any problems!
ipconfig只调出内部 IP 地址,而我运行的所有服务都使用外部 IP,没有任何问题!
Any ideas?
有任何想法吗?
采纳答案by Rosh Oxymoron
That's an error Windows gives when you're trying to bind to an address on the local machine that's not assigned to any of the adapters on the machine. If ipconfigdoesn't show it, you can't bind to it.
这是当您尝试绑定到本地机器上未分配给机器上任何适配器的地址时 Windows 给出的错误。如果ipconfig不显示它,则无法绑定到它。
If the external address is on a router that is NAT'ing requests from it to the server's internal address, you can't bind to it because it's on a different machine. This is probably the case. You might want to bind to socket.INADDR_ANY(or its Django equivalent). This will bind to all addresses that are on the machine right now.
如果外部地址位于路由器上,该路由器将请求从它发送到服务器的内部地址,则您无法绑定到它,因为它位于不同的机器上。大概就是这种情况。您可能想要绑定到socket.INADDR_ANY(或其 Django 等效项)。这将绑定到当前机器上的所有地址。
Also note that if the external address is NAT'ed to your internal one, binding to the internal one should be enough.
另请注意,如果外部地址已通过 NAT 转换为内部地址,则绑定到内部地址就足够了。

