views:

604

answers:

3

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.

A: 

www.google.com is not accessible by HTTPS. It redirects to insecure HTTP. To get to mail, you should be going go https://mail.google.com

$ curl -i https://www.google.com/ HTTP/1.1 302 Found [...]
aaronsw
+1  A: 
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.

Marcel
A: 

The first thing I would check is whether you need to connect via an HTTP proxy (in which case direct connections bypassing the proxy will likely time out). Run Wireshark and see what happens.

Alexander