Hướng dẫn python requests bad handshake certificate verify failed - python yêu cầu chứng chỉ bắt tay xấu xác minh không thành công

Cố gắng thực hiện một yêu cầu nhận đơn giản bằng cách sử dụng phiên yêu cầu nhưng tôi tiếp tục nhận được SSLError cho một trang web cụ thể. Tôi nghĩ rằng có lẽ vấn đề là với trang web [tôi đã quét bằng cách sử dụng //www.ssllabs.com, kết quả đã xuống dưới đây], nhưng tôi không thể chắc chắn vì tôi không có kiến ​​thức trong lĩnh vực này :] Tôi chắc chắn muốn để hiểu những gì đang xảy ra.

Một giải pháp/giải thích sẽ rất tuyệt, cảm ơn!

Mật mã:

import requests

requests.get['//www.reporo.com/']

Tôi đang gặp lỗi tiếp theo:

SSLError: [Errno bad handshake] [['SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed']]

---------------------------------------------------------------------------
SSLError                                  Traceback [most recent call last]
 in []
----> 1 requests.get['//www.reporo.com/']

/usr/local/lib/python2.7/dist-packages/requests/api.pyc in get[url, **kwargs]
     63 
     64     kwargs.setdefault['allow_redirects', True]
---> 65     return request['get', url, **kwargs]
     66 
     67 

/usr/local/lib/python2.7/dist-packages/requests/api.pyc in request[method, url, **kwargs]
     47 
     48     session = sessions.Session[]
---> 49     response = session.request[method=method, url=url, **kwargs]
     50     # By explicitly closing the session, we avoid leaving sockets open which
     51     # can trigger a ResourceWarning in some cases, and look like a memory leak

/usr/local/lib/python2.7/dist-packages/requests/sessions.pyc in request[self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json]
    459         }
    460         send_kwargs.update[settings]
--> 461         resp = self.send[prep, **send_kwargs]
    462 
    463         return resp

/usr/local/lib/python2.7/dist-packages/requests/sessions.pyc in send[self, request, **kwargs]
    571 
    572         # Send the request
--> 573         r = adapter.send[request, **kwargs]
    574 
    575         # Total elapsed time of the request [approximately]

/usr/local/lib/python2.7/dist-packages/requests/adapters.pyc in send[self, request, stream, timeout, verify, cert, proxies]
    429         except [_SSLError, _HTTPError] as e:
    430             if isinstance[e, _SSLError]:
--> 431                 raise SSLError[e, request=request]
    432             elif isinstance[e, ReadTimeoutError]:
    433                 raise ReadTimeout[e, request=request]

SSLError: [Errno bad handshake] [['SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed']]

Tôi đã thực hiện quét tại //www.ssllabs.com và nhận được như sau:

SSL Report: reporo.com
Assessed on:  Sun Feb 22 21:42:57 PST 2015 | Clear cache Scan Another >>

    Server  Domain[s]   Test time   Grade
1   154.51.128.13 
Certificate not valid for domain name 
reporo.com
Sun Feb 22 21:40:53 PST 2015 
Duration: 9.167 sec -
2   198.12.15.168 
protected.ddosdefend.com 
Ready 
www.reporo.com

Sun Feb 22 21:41:02 PST 2015 
Duration: 115.189 sec   
F

Xin chào. Tôi đang cố gắng kết nối với một máy chủ với HTTPS. Tôi có chứng chỉ là chứng chỉ tự ký đang được đưa vào tham số xác minh nhưng kết quả là lỗi 'Chứng chỉ xác minh lỗi không thành công'. Tôi đã nghi ngờ nó phải làm với chứng chỉ được tự ký [bởi Microsoft IIS] nhưng với Curl, điều này hoạt động. Cảm ơn trước!
Thanks in advance!

Đây là đầu ra OpenSSL:

openssl s_client -showcerts -connect server:44300
CONNECTED[00000003]
depth=0 CN = server
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 CN = server
verify error:num=21:unable to verify the first certificate
verify return:1
---
Certificate chain
 0 s:/CN=server
   i:/CN=server
-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----
---
Server certificate
subject=/CN=server
issuer=/CN=server
---
No client certificate CA names sent
Peer signing digest: SHA1
Server Temp Key: ECDH, P-256, 256 bits
---
SSL handshake has read 1477 bytes and written 431 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES256-GCM-SHA384
    Session-ID: CC4A000083B1E03B446416C9C0B16CBEAB79949E3CF5C936A309A6F92FA01364
    Session-ID-ctx:
    Master-Key: 798A570B0EC2A0CBB7C4C4DE6167E7579A92239942D869CD794B8BEBEA6EB5E492394634AD32665A8BB829DE1F3858D2
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1510329948
    Timeout   : 300 [sec]
    Verify return code: 21 [unable to verify the first certificate]
---

Kết quả dự kiến

Tôi đang mong đợi, vì chứng chỉ nằm trong tham số xác minh, rằng kết nối sẽ không bị lỗi. Nếu tôi thử tương tự với Curl bên ngoài Python, nó hoạt động:

curl //server:44300 --cacert /usr/share/ca-certificates/server.crt
 HTTP/1.1 403 Forbidden
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Content-Length: 1158
Content-Type: text/html
Server: Microsoft-IIS/10.0
X-Frame-Options: SAMEORIGIN
P3P: CP=None
Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS
Access-Control-Allow-Headers: X-Requested-With,Content-Type
Access-Control-Allow-Credentials: true
Date: Fri, 10 Nov 2017 16:02:26 GMT

[Nó thất bại nhưng không phải vì vấn đề chứng chỉ]

Kết quả thực tế

Traceback [most recent call last]:
  File "", line 1, in 
  File "xxxxx/TestVirtualEnv/local/lib/python2.7/site-packages/requests/api.py", line 72, in get
    return request['get', url, params=params, **kwargs]
  File "xxxxx/TestVirtualEnv/local/lib/python2.7/site-packages/requests/api.py", line 58, in request
    return session.request[method=method, url=url, **kwargs]
  File "xxxxx/TestVirtualEnv/local/lib/python2.7/site-packages/requests/sessions.py", line 508, in request
    resp = self.send[prep, **send_kwargs]
  File "xxxxx/TestVirtualEnv/local/lib/python2.7/site-packages/requests/sessions.py", line 618, in send
    r = adapter.send[request, **kwargs]
  File "xxxxx/TestVirtualEnv/local/lib/python2.7/site-packages/requests/adapters.py", line 506, in send
    raise SSLError[e, request=request]
requests.exceptions.SSLError: HTTPSConnectionPool[host='nlybstqvp4nb75n.code1.emi.philips.com', port=44300]: Max retries exceeded with url: / [Caused by SSLError[SSLError["bad handshake: Error[[['SSL routines', 'tls_process_server_certificate', 'certificate verify failed']],]",],]]

Các bước tái tạo

import requests
requests.get['//server:44300', verify='/usr/share/ca-certificates/server.crt']

Thông tin hệ thống

$ python -m requests.help

{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": "2.1.3"
  },
  "idna": {
    "version": "2.6"
  },
  "implementation": {
    "name": "CPython",
    "version": "2.7.12"
  },
  "platform": {
    "release": "4.10.0-38-generic",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "1010007f",
    "version": "17.3.0"
  },
  "requests": {
    "version": "2.18.4"
  },
  "system_ssl": {
    "version": "1000207f"
  },
  "urllib3": {
    "version": "1.22"
  },
  "using_pyopenssl": true
}

Lệnh này chỉ có sẵn trên các yêu cầu v2.16.4 và lớn hơn. Nếu không, vui lòng cung cấp một số thông tin cơ bản về hệ thống của bạn [phiên bản Python, hệ điều hành, & c].
please provide some basic information about your system [Python version,
operating system, &c].

Lỗi bắt tay xấu là gì?

Bắt tay SSL không thành công là một thông báo lỗi xảy ra khi máy khách hoặc máy chủ không thể thiết lập kết nối an toàn.Điều này có thể xảy ra nếu: Khách hàng đang sử dụng sai ngày hoặc thời gian.an error message that occurs when the client or server wasn't able to establish a secure connection. This might occur if: The client is using the wrong date or time.

Điều gì gây ra lỗi chứng chỉ SSL Python?

Điều gì gây ra lỗi ssl chứng chỉ_verify_fails?SSL Chứng chỉ_verify_fails Các lỗi thường xảy ra do chứng chỉ mặc định Python lỗi thời hoặc chứng chỉ gốc không hợp lệ.Nếu bạn là chủ sở hữu trang web và bạn đang nhận lỗi này, đó có thể là do bạn không sử dụng chứng chỉ SSL hợp lệ.outdated Python default certificates or invalid root certificates. If you're a website owner and you're receiving this error, it could be because you're not using a valid SSL certificate.

Giấy chứng nhận xác minh có nghĩa là gì?

Chứng chỉ lỗi Ruby OpenSSL Xác minh không thành công có nghĩa là mã của bạn không thể xác minh rằng chứng chỉ SSL của Trang web hoặc API mà bạn đang kết nối là thật.Điều quan trọng là phải giải quyết vấn đề này một cách chính xác để giữ an toàn cho giao tiếp của bạn.your code can't verify that the SSL certificate of the website or API you're connecting to is the real one. It's important to solve this issue correctly to keep your communication secure.

Yêu cầu Python có sử dụng HTTPS không?

Yêu cầu xác minh chứng chỉ SSL cho các yêu cầu HTTPS, giống như trình duyệt web., just like a web browser.

Chủ Đề