close

[Solved] Win 10049: The requested address is not valid in its context

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Win 10049: The requested address is not valid in its context in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Win 10049: The requested address is not valid in its context Error Occurs?

Today I get the following error Win 10049: The requested address is not valid in its context in python.

How To Solve Win 10049: The requested address is not valid in its context Error ?

  1. How To Solve Win 10049: The requested address is not valid in its context Error ?

    To Solve Win 10049: The requested address is not valid in its context Error First, you must connect both devices to the same network. Then, for the server.py (or anything you want to call it)

  2. Win 10049: The requested address is not valid in its context

    To Solve Win 10049: The requested address is not valid in its context Error First, you must connect both devices to the same network. Then, for the server.py (or anything you want to call it)

Solution 1

from socket import *
soc = socket(AF_INET, SOCK_STREAM)
soc.connect(('168.62.48.183', 80))
soc.send('GET /miners/get?file=BFGMiner-3.99-r.1-win32.zip HTTP/1.1\nUser-Agent:MultiMiner/V3\nHost: www.multiminerapp.com\n')
with open("http-response.txt","w") as respfile:
    response = soc.recv(1024) # <--- Use select.epoll or asyncore instead!
    respfile.writelines(response)

The reason for why your code fails tho is because you’re trying to bind to an external IP.
Your machine is not aware of this IP hence the error message, if you’d change it to say 127.0.0.1 it would work, but then again you would need a .listen(4) and ns, na = soc.accept() before utelizing .send() and your soc.recv() would need to be ns.recv(1024).

In other words, you mixed up client sockets with server sockets and you’re binding to a IP not present on the local machine.

Also notesoc.recv() will fail, you need a buffer-size argument like so: soc.recv(1024)

Python3:

from socket import *
soc = socket(AF_INET, SOCK_STREAM)
soc.connect(('168.62.48.183', 80))
soc.send(b'GET /miners/get?file=BFGMiner-3.99-r.1-win32.zip HTTP/1.1\nUser-Agent:MultiMiner/V3\nHost: www.multiminerapp.com\n\n') # Note the double \n\n at the end.
with open("http-response.txt","wb") as respfile:
    response = soc.recv(8192)
    respfile.write(response)

There’s two major differences, we send a binary GET /miners/.. string rather than a standard string. Secondly we open the output-file in a binary form because the data recieved will also be in binary form..

This is because Python no longer decodes the string for you because of a number of reasons, so you need to either treat the data as binary or manually decode it along the way.

You should probably:

import urllib.request
f = urllib.request.urlopen("http://www.multiminerapp.com/miners/get?file=BFGMiner-3.99-r.1-win32.zip")
print(f.read())

Solution 2

First, you must connect both devices to the same network. Then, for the server.py (or anything you want to call it)

Use

soc.bind(('', PORT))

Instead of

soc.bind(('IP', PORT))

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read