Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python sockets suddenly timing out?

I came back today to an old script I had for logging into Gmail via SSL. The script worked fine last time I ran it (several months ago) but now it dies immediately with:

<urlopen error The read operation timed out>

If I set the timeout (no matter how long), it dies even more immediately with:

<urlopen error The connect operation timed out>

The latter is reproducible with:

import socket
socket.setdefaulttimeout(30000)
sock = socket.socket()
sock.connect(('www.google.com', 443))
ssl = socket.ssl(sock)

returning:

socket.sslerror: The connect operation timed out

but I can't seem to reproduce the former and, after much stepping thru the code, I have no clue what's causing any of this.

like image 314
aaronsw Avatar asked Sep 18 '08 13:09

aaronsw


1 Answers

import socket
socket.setdefaulttimeout(30000)
sock = socket.socket()
sock.connect(('www.google.com', 443))
ssl = socket.ssl(sock)
ssl.server()
--> '/C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com'

It works just fine. I can't reproduce your error.

like image 52
defnull Avatar answered Sep 28 '22 04:09

defnull