The requested address is not valid in its context error

前端 未结 2 851
粉色の甜心
粉色の甜心 2021-01-18 07:08

I was following a tutorial called \"Black Hat Python\" and got a \"the requested address is not valid in its context\" error. I\'m Python IDE version: 2.7.12 This is my code

相关标签:
2条回答
  • 2021-01-18 07:54

    You are trying to bind to an IP address that is not actually assigned to your network interface:

    bind_ip = "184.168.237.1"
    

    See the Windows Sockets Error Codes documentation:

    WSAEADDRNOTAVAIL 10049
    Cannot assign requested address.

    The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for the local computer.

    That may be an IP address that your router is listening to before using NAT (network address translation) to talk to your computer, but that doesn't mean your computer sees that IP address at all.

    Either bind to 0.0.0.0, which will use all available IP addresses (both localhost and any public addresses configured):

    bind_ip = "0.0.0.0"
    

    or use any address that your computer is configured for; run ipconfig /all in a console to see your network configuration.

    You probably also don't want to use ports < 1024; those are reserved for processes running as root only. You'll have to pick a higher number than that if you want to run an unprivileged process (and in the majority of tutorials programs, that is exactly what you want):

    port = 5021  # arbitrary port number higher than 1023
    

    I believe the specific tutorial you are following uses BIND_IP = '0.0.0.0' and BIND_PORT = 9090.

    0 讨论(0)
  • 2021-01-18 08:04

    I was just getting this error while following this Python TCP example and the solution was to have my client connect using 'localhost' instead of '0.0.0.0'.

    0 讨论(0)
提交回复
热议问题