Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

python - Discord.py unable to get certificate

Do I have to install/generate/download new certificate inside my system or is it possible for me somehow to disable certificates inside the python? (ubuntu 18, python 3.7, discord.py latest)

[INFO]  [2019.03.05 - 22:58:02]   Initializing Discord...

SSL handshake failed on verifying the certificate
protocol: <asyncio.sslproto.SSLProtocol object at 0xf4a9f8ec>
transport: <_SelectorSocketTransport fd=12 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "./build/Lib/asyncio/sslproto.py", line 625, in _on_handshake_complete
  File "./build/Lib/asyncio/sslproto.py", line 189, in feed_ssldata
  File "./build/Lib/ssl.py", line 763, in do_handshake
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1051)

SSL error in data received
protocol: <asyncio.sslproto.SSLProtocol object at 0xf4a9f8ec>
transport: <_SelectorSocketTransport closing fd=12 read=idle write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "./build/Lib/asyncio/sslproto.py", line 526, in data_received
  File "./build/Lib/asyncio/sslproto.py", line 189, in feed_ssldata
  File "./build/Lib/ssl.py", line 763, in do_handshake
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1051)

[ERROR] [2019.03.05 - 22:58:02]   
2019.03.05 - 22:58:02:
  Top:  file: [sv_custom.py], method: init()
  Root: file: [connector.py], line 974, cause: in _create_direct_connection [File "./../source/aiohttp.whl/aiohttp/connector.py", line 927, in _wrap_create_connection]
  aiohttp.client_exceptions.ClientConnectorCertificateError:
  Cannot connect to host discordapp.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1051)')]

This is done from the python that is inside the game client. If I do the same from the system's python (3.6) - no errors, connection is fine. "They say" it could be because the game client does not see "root certificates" or something like that.

Update: Found out how to check certificates.

(with ssl error)
Initializing Discord...
DefaultVerifyPaths(cafile=None, capath=None, openssl_cafile_env='SSL_CERT_FILE', openssl_cafile='/usr/local/ssl/cert.pem', openssl_capath_env='SSL_CERT_DIR', openssl_capath='/usr/local/ssl/certs')


(this works fine)
igor@Linbox:~/Downloads$ python3.6 -c "import ssl; print(ssl.get_default_verify_paths())"
DefaultVerifyPaths(cafile=None, capath='/usr/lib/ssl/certs', openssl_cafile_env='SSL_CERT_FILE', openssl_cafile='/usr/lib/ssl/cert.pem', openssl_capath_env='SSL_CERT_DIR', openssl_capath='/usr/lib/ssl/certs')

Guess that is my problem that capath is empty.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Unexpectedly the solution appeared quite simple:

ssl.get_default_verify_paths() for the python with the ssl error was pointing to: openssl_capath='/usr/local/ssl/certs' while the "native" python from the system showed openssl_capath='/usr/lib/ssl/certs'.

DefaultVerifyPaths(
  cafile=None,
  capath=None,
  openssl_cafile_env='SSL_CERT_FILE',
  openssl_cafile='/usr/local/ssl/cert.pem',
  openssl_capath_env='SSL_CERT_DIR',
  openssl_capath='/usr/local/ssl/certs'
)

I've checked both locations: '/usr/local/' - was empty (it had no ssl/certs folders) '/usr/lib/ssl/certs' had a symlink to '/etc/ssl/certs' So I made the same symlink: inside '/usr/local/' added '/ssl/' + ln -s '/etc/ssl/certs' certs

Then I checked once again ssl.get_default_verify_paths()

DefaultVerifyPaths(
  cafile=None,
  capath='/usr/local/ssl/certs',  <-- not empty now
  openssl_cafile_env='SSL_CERT_FILE',
  openssl_cafile='/usr/local/ssl/cert.pem',
  openssl_capath_env='SSL_CERT_DIR',
  openssl_capath='/usr/local/ssl/certs'
)

The problem disappeared. It is working now.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...