OSError: [WinError 10049] The requested address is not valid in its context
Your system might have many ip addresses assigned to it. In windows you can see by ipconfig /all command. But only one ip address is external. You need to bind to that ip address for your freinds to connect to you. If your system is connected through wifi, then it will be your wifi adapter ip address.
OSError: [WinError 10049] How do I tackle this error?
You have to change the IP address in the bind
command of the socket to the IP address of device which is offering the server, i.e. the address of your own pc. The code you posted here is not going to do what you want to do: it will create a new server
and will not act as a client which can connect to a server!
This lines
self.server_socket.bind(('192.168.0.6', 8081))
self.server_socket.listen(0)
have to be replaced with
self.socket.connect(('192.168.0.6', 8081))
Edit: Maybe it is better to use the create_connection
function, as it operates on a higher API level. So you will end up with this initialization method:
def __init__(self):
self.socket = socket.socket()
self.connection, _ = self.socket.create_connection(('192.168.0.6', 8081))
self.streaming()
In the streaming
method you then have to remove this line, also:
print ("Connection from: ", self.client_address)
The requested address is not valid in its context error
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
.
Related Topics
How to Solve and Equation With Inputs in Python
How to Avoid Last Comma in Python Loop
How to Find the Average of Particular Numbers in a CSV File
How to Save Opened Page as Pdf in Selenium (Python)
How to Tell Python to Convert Integers into Words
What Else Do I Need for Codehs 8.3.8: Word Ladder
How to Run an .Ipynb Jupyter Notebook from Terminal
How to Strip Comma in Python String
Visual Studio Code Pylint: Unable to Import 'Protorpc'
Strip White Spaces from CSV File
Python - How to Sort a List of Alpha and Numeric Values
Cv2 Image Error: Error: (-215:Assertion Failed) !Ssize.Empty() in Function 'Cv::Resize'
No Unique Mode; Found 2 Equally Common Values
Anaconda Installed But Cannot Launch Navigator
How to Write 2 Lists of Items in 2 Columns Instead of 2 Arrays
Python: Create 50 Objects Using a for Loop
Maximum Characters That Can Be Stuffed into Raw_Input() in Python