简体   繁体   中英

python socket.connect timeout

i've got some problem with connecting to irc server. Yesterday code attached below worked fine, but today i got error.

print('Script started')
network = 'irc.quakenet.org'
port = 6667
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.settimeout(180.0)
print(irc.gettimeout())
**irc.connect((network, port))**

In the log i get this:

Script started 180.0 Traceback (most recent call last): File "C:\\Users...\\TM_bot1\\src\\connectBot.py", line 66, in irc.connect((network, port)) TimeoutError: [WinError 10060] [ErrMsg]

In code line which returns error is bolded.

My question is, is it a real issue with server availability? With mIRC agent i've no problems to connect to the same server and port.

**Answears for posted below questions: It's not connected to proxy. As mentioned before - yesterday everything was working ok, and since then i haven't changed anything. I get this error before 180 seconds.

Now, after few hours - script is working ok, so it seems to be server overload issue. Is there any way to extend timeout?

I was having issues with the timeout setting with socket. I found this

http://code.activestate.com/recipes/576655-wait-for-network-service-to-appear/

which addresses http://bugs.python.org/issue5293

Essentially, the recipe performs it's own timeout, since timeouts over 20 seconds appear to be ignored with socket, as there's another shorter timeout that kicks in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM