GHC 2016-11-23

4 comments.

, https://git.io/v1KUz in jarun/googler
> Did you try to use tor and privoxy?

privoxy. It's not a connection blocked by Google problem, as 1. connection failure occurs during connection to the proxy server; 2. works on Python 3.4. No idea why.

> Why do you think the second branch is the problem here

Not saying it's the problem here, just making a general comment that it looks suspicious.

, https://git.io/v1KUg in jarun/googler
Okay, after a bit of messing around, I realized I have no idea of

```python
        if getattr(self, '_tunnel_host', None):
            self.sock = sock
            self._tunnel()
            HTTPSConnection.connect(self)
        elif not notweak and sys.version_info >= (3,4):
            # Use TLS 1.2
            self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file,
                    ssl_version=ssl.PROTOCOL_TLSv1_2)
        else:
            HTTPSConnection.connect(self)
```

Relying on undocumented internals is probably not a good idea, and the second branch looks suspicious.

I'm bowing out from this issue since that's all I can say. Oh, and this patch which bypasses `TLS1_2Connection` in favor of good ol' `HTTPSConnection` should work for you @xzdbd at least before the problem is worked out:

```diff
diff --git a/googler b/googler
index aca5a37..db95a0f 100755
--- a/googler
+++ b/googler
@@ -597,21 +597,21 @@ class GoogleConnection(object):
         proxy = self._proxy
         if proxy:
             logger.debug('Connecting to proxy server %s', proxy)
-            self._conn = TLS1_2Connection(proxy, timeout=timeout)
+            self._conn = HTTPSConnection(proxy, timeout=timeout)
 
             logger.debug('Tunnelling to host %s' % host_display)
             self._conn.set_tunnel(host, port=port)
 
             try:
-                self._conn.connect(self._notweak)
+                self._conn.connect()
             except Exception as e:
                 msg = 'Failed to connect to proxy server %s: %s.' % (proxy, e)
                 raise GoogleConnectionError(msg)
         else:
             logger.debug('Connecting to new host %s', host_display)
-            self._conn = TLS1_2Connection(host, port=port, timeout=timeout)
+            self._conn = HTTPSConnection(host, port=port, timeout=timeout)
             try:
-                self._conn.connect(self._notweak)
+                self._conn.connect()
             except Exception as e:
                 msg = 'Failed to connect to %s: %s.' % (host_display, e)
                 raise GoogleConnectionError(msg)
```

, https://git.io/v1KU2 in jarun/googler
> When you are using Python 3.3, just HTTPSConenction is used and it supports proxies too.

Hmm I glanced at the code and missed the `sys.version_info >= (3,4)` condition. Yeah, that's designed to work, but at least the class name is a misnomer in that case.

By the way, I can reproduce the failure on 3.3.6 too.

```
$ googler --debug --proxy localhost:8118 hello
[DEBUG] Version 2.8
[DEBUG] Connecting to proxy server localhost:8118
[DEBUG] Tunnelling to host www.google.com
Traceback (most recent call last):
  File "/Users/zmwang/dev/src/forks/googler/googler", line 606, in new_connection
    self._conn.connect(self._notweak)
  File "/Users/zmwang/dev/src/forks/googler/googler", line 162, in connect
    HTTPSConnection.connect(self)
  File "/Users/zmwang/.pyenv/versions/3.3.6/lib/python3.3/http/client.py", line 1202, in connect
    self._tunnel()
  File "/Users/zmwang/.pyenv/versions/3.3.6/lib/python3.3/http/client.py", line 803, in _tunnel
    (version, code, message) = response._read_status()
  File "/Users/zmwang/.pyenv/versions/3.3.6/lib/python3.3/http/client.py", line 320, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/Users/zmwang/.pyenv/versions/3.3.6/lib/python3.3/socket.py", line 297, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/zmwang/dev/src/forks/googler/googler", line 2184, in <module>
    main()
  File "/Users/zmwang/dev/src/forks/googler/googler", line 2158, in main
    repl = GooglerCmd(opts)
  File "/Users/zmwang/dev/src/forks/googler/googler", line 1581, in __init__
    notweak=opts.notweak)
  File "/Users/zmwang/dev/src/forks/googler/googler", line 565, in __init__
    self.new_connection(host, port=port, timeout=timeout)
  File "/Users/zmwang/dev/src/forks/googler/googler", line 609, in new_connection
    raise GoogleConnectionError(msg)
__main__.GoogleConnectionError: Failed to connect to proxy server localhost:8118: [Errno 54] Connection reset by peer.
```

I'll look into it in a bit.

, https://git.io/v1KUa in jarun/googler
@jarun Two notes:

1. `ssl.PROTOCOL_TLSv1_2` has been deprecated since Python 3.5.3. [Ref](https://docs.python.org/3/library/ssl.html#ssl.PROTOCOL_TLSv1_2):

    > OpenSSL has deprecated all version specific protocols. Use the default protocol data:PROTOCOL_TLS with flags like data:OP_NO_SSLv3 instead.

    So this needs to be addressed.

2. I think we should provide a fallback for Python 3.3. Utility probably trumps security for many people, not to mention there's not much to be mined from or poisoned in an anonymous Google Search. People who really cares about security should probably not be using Python 3.3 anyway, which is approaching EOL.