Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a troublesome problem socket.error error: [Errno 10048]: Address already in use. Only one usage of each socket address (protocol/IP address/port) is normally permitted during automated tests using Selenium with Python. The problem is so interesting that it runs on one machine (Linux) works correctly, but on another machine (WindowsXP) generates this error. I would add that the problem arose after the reinstallation of the system and set up all over again - with the previous configuration everything worked properly. Is there maybe something I forgot? Has anyone come up with such a problem before?

Does anyone have an idea of ​​how to deal with this problem?

The current configuration / libraries:

python 2.7, numpy, selenium.py

share|improve this question
    
Which port does it use? –  wong2 May 30 '11 at 12:50
    
Selenium runs on port 4444 by default –  falek.marcin May 30 '11 at 13:13
add comment

4 Answers

If you open/close the socket multiple times, it could be in the TIME_WAIT state. This would explain why it acts differently on separate platforms (different TIME_WAIT settings and TCP stack). If you're controlling the socket object, you can set SO_REUSEADDR before binding to fix the problem.

For example:

sock = socket.socket()
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, server.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR) | 1)

You can run netstat -b from the command prompt to give you a list of open sockets with the state and owning process.

share|improve this answer
add comment
up vote 1 down vote accepted

I found the answer in the post below:

Python urllib2. URLError: <urlopen error [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted>

It turned out that this problem is limitation of Windows

share|improve this answer
add comment

There are several possibilities. If none of your tests can listen on some port (you don't say what port) then perhaps your Windows machine is running something on a port that you previously had open; this new service may have appeared during the reinstall. If, on the other hand, it's only a problem for some tests, or it's a little sporadic, then it may be either a programming issue (forgetting to close a socket in an early test which interferes with a later one) or a timing issue (the earlier test's socket isn't quite through closing before the new one tries to open up). Obviously there are different ways to address each of these problems, but I don't think we can help more than this without more details.

share|improve this answer
add comment

Maybe there is a software on your Windows that already use port 4444, can you try set Selenium to another port and try again?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.