title: Python cannot bind my external/public IP address using socket, gives error But when using local IP address the error doesn't show up
body: <p>Here is the code where the main error shows up</p>
  <p>A bind with my local IP will work:</p>
  <pre class="lang-py prettyprint-override"><code>s.bind((&quot;192.168.1.4&quot;, port))
  </code></pre>
  <p>A bind with my public IP fails with the error below</p>
  <pre class="lang-py prettyprint-override"><code>s.bind((&quot;99.99.99.99&quot;, port))
  </code></pre>
  <blockquote>
  <p>[WinError 10049] The requested address is not valid in its context</p>
  </blockquote>
  <p>Here is more context about my code:</p>
  <pre class="lang-py prettyprint-override"><code>
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  
  port = 6767
  
  try:
      s.bind((&quot;192.168.1.4&quot;, port))  # will work fine as local ip is used but 
                                     # when used public ip the error is thrown
  except socket.error as e:
      print(str(e)+&quot;aa&quot;)
  
  s.listen(2)
  </code></pre>