jarun / googler

:mag: Google from the terminal
GNU General Public License v3.0
6.1k stars 528 forks source link

ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123) #391

Closed ChesterYue closed 3 years ago

ChesterYue commented 3 years ago

[DEBUG] googler version 4.3.1 [DEBUG] Python version 3.9.1 [DEBUG] Platform: macOS-11.1-x86_64-i386-64bit [DEBUG] Connecting to new host www.google.com [DEBUG] Opened socket to 157.240.8.41:443 Traceback (most recent call last): File "/usr/local/bin/googler", line 2138, in new_connection self._conn.connect(self._notweak) File "/usr/local/bin/googler", line 1602, in connect self.sock = ssl_context.wrap_socket(sock) File "/usr/local/Cellar/python@3.9/3.9.1_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 500, in wrap_socket return self.sslsocket_class._create( File "/usr/local/Cellar/python@3.9/3.9.1_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1040, in _create self.do_handshake() File "/usr/local/Cellar/python@3.9/3.9.1_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1309, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/bin/googler", line 3792, in main() File "/usr/local/bin/googler", line 3765, in main repl = GooglerCmd(opts) File "/usr/local/bin/googler", line 2765, in init self._conn = GoogleConnection(self._google_url.hostname, File "/usr/local/bin/googler", line 2079, in init self.new_connection(host, port=port, timeout=timeout) File "/usr/local/bin/googler", line 2141, in new_connection raise GoogleConnectionError(msg) main.GoogleConnectionError: Failed to connect to www.google.com: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123).

jarun commented 3 years ago

I don't see this on Ubuntu 20.04 with latest updates. @zmwangx can you please take a look?

zmwangx commented 3 years ago

Can't reproduce on same platform (macOS-11.1-x86_64-i386-64bit), same Homebrew Python version, and same googler version. I doubt this is on our end, or on Homebrew's Python in general. However, just to clear it up, run the following scripts and report results:

httpclient.py:

#!/usr/local/opt/python/bin/python3
import http.client
import sys

conn = http.client.HTTPSConnection("google.com")
conn.request("GET", "https://google.com")
resp = conn.getresponse()
print(f"HTTP {resp.status}")
sys.stdout.buffer.write(resp.read())

urllibrequest.py:

#!/usr/local/opt/python/bin/python3
import sys
import urllib.request

resp = urllib.request.urlopen('https://google.com')
print(f"HTTP {resp.status}")
sys.stdout.buffer.write(resp.read())

Make sure you use the Homebrew Python, of course (chmod +x the scripts then invoking them directly would take care of that).

zmwangx commented 3 years ago

Also:

/usr/local/opt/python/bin/python3 -c 'import ssl; print(ssl.OPENSSL_VERSION)'
ChesterYue commented 3 years ago

I find out this issue caused by the proxy firewall in my office. It's handy to use googler in my home. thank you guys!