套接字错误“IP地址在其上下文中无效” - Python [英] Socket error "IP address not valid in its context" - Python
问题描述
我使用的是 Python 2.6 和 Windows Server 2008 。
服务器具有 IP地址1内部,1外部。
我需要Python来使用外部IP地址,但是在这样做时,我得到这个:
socket.error:[错误10049]请求的地址无效它的上下文
socket.error: [Error 10049] The requested address is not valid in its context
为了更准确地说,我正在使用Django的runserver命令,熟悉它
To be more precise I'm using Django's runserver command for who is familiar with it
ipconfig
只会打开内部IP地址,而我所有运行的服务都使用外部IP而没有任何问题!
ipconfig
only brings up the internal IP address, while all services I have running are using the external IP without any problems!
任何想法?
推荐答案
这是Windows尝试绑定时出现的错误本地机器上没有分配给任何适配器的地址rs在机器上。如果 ipconfig
不显示,则无法绑定到它。
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 ipconfig
doesn't show it, you can't bind to it.
如果外部地址位于将NAT请求从服务器的内部地址的路由器上,则无法绑定到它,因为它位于不同的机器上。可能是这样。您可能需要绑定到 socket.INADDR_ANY
(或其Django等效项)。这将绑定到现在机器上的所有地址。
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.
另请注意,如果外部地址是NAT内部的,绑定到内部地址应该够了。
Also note that if the external address is NAT'ed to your internal one, binding to the internal one should be enough.
这篇关于套接字错误“IP地址在其上下文中无效” - Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!