python错误号码ssl

python错误号码ssl,python,sockets,ssl,Python,Sockets,Ssl,我一直在尝试通过ssl加密的低级套接字模块连接到google geocoder api。在这里的API_key_位置,我实际上在脚本中有自己的API 每次执行脚本时,我都会从ssl“ssl.SSLError:[ssl:error\u VERSION\u NUMBER]error VERSION NUMBER(\u ssl.c:847)”中得到以下错误 我运行的是LinuxMint,Python是3.6 import socket from urllib.parse import quote_pl

我一直在尝试通过ssl加密的低级套接字模块连接到google geocoder api。在这里的API_key_位置,我实际上在脚本中有自己的API

每次执行脚本时,我都会从ssl“ssl.SSLError:[ssl:error\u VERSION\u NUMBER]error VERSION NUMBER(\u ssl.c:847)”中得到以下错误 我运行的是LinuxMint,Python是3.6

import socket
from urllib.parse import quote_plus
import ssl

key = "API_key_here"
text = """\
GET /maps/api/geocode/json?key={}&address={}&sensor=false HTTP/1.1\r\n
Host: maps.google.com:80\r\n
User-Agent: 1-4-socket-geocoding-py-network.py\r\n
Connection: close\r\n
"""


def geocode(address):
    sock = socket.socket()
    context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)

    sock_ssled = context.wrap_socket(sock, server_hostname="maps.google.com")
    print(sock_ssled.version)
    context.verify_mode = ssl.CERT_REQUIRED
    context.check_hostname = True
    sock_ssled.connect(("maps.google.com", 80))
    request = text.format(key, quote_plus(address))

    sock_ssled.sendall(request.encode("ascii"))
    rawreply =b""
    while True:
        more = sock_ssled.recv(4096)
        if not more:
            break
        rawreply += more
    print (rawreply.decode("utf-8")) 

if __name__ == "__main__":
    geocode ('207 N. Defiance St, Archbold, OH')
下面是错误输出

    <bound method SSLSocket.version of <ssl.SSLSocket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('0.0.0.0', 0)>>
Traceback (most recent call last):
  File "/home/user1/pyenv1/scripts/1-4-socket-geocoding-py-network.py", line 36, in <module>
    geocode ('207 N. Defiance St, Archbold, OH')
  File "/home/user1/pyenv1/scripts/1-4-socket-geocoding-py-network.py", line 23, in geocode
    sock_ssled.connect(("maps.google.com", 80))
  File "/usr/lib/python3.6/ssl.py", line 1109, in connect
    self._real_connect(addr, False)
  File "/usr/lib/python3.6/ssl.py", line 1100, in _real_connect
    self.do_handshake()
  File "/usr/lib/python3.6/ssl.py", line 1077, in do_handshake
    self._sslobj.do_handshake()
  File "/usr/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:847)

回溯(最近一次呼叫最后一次):
文件“/home/user1/pyenv1/scripts/1-4-socket-geocoding-py-network.py”,第36行,在
地理编码('207 N.迪法恩斯街,阿奇博尔德,俄亥俄州')
文件“/home/user1/pyenv1/scripts/1-4-socket-geocoding-py-network.py”,第23行,地理编码
sock_ssled.connect((“maps.google.com”,80))
文件“/usr/lib/python3.6/ssl.py”,第1109行,在connect中
self.\u real\u connect(地址,错误)
文件“/usr/lib/python3.6/ssl.py”,第1100行,在real\u connect中
self.do_握手
文件“/usr/lib/python3.6/ssl.py”,第1077行,在do_握手中
赛尔夫:握手
文件“/usr/lib/python3.6/ssl.py”,第689行,在do_握手中
赛尔夫:握手
ssl.SSLError:[ssl:error\u VERSION\u NUMBER]error VERSION NUMBER(\u ssl.c:847)

您可能应该连接到端口443,而不是80。80代表普通HTTP,443代表HTTPS。

您可能应该连接到端口443,而不是80。80代表普通HTTP,443代表HTTPS。

Omg我应该意识到,当未附加证书时,必须添加.for me verify=False访问HTTPS://我应该意识到当未附加证书时,必须添加.for me verify=False访问HTTPS://