与Salesforce的Python连接无法通过证书验证

时间:2019-02-06 21:21:56

标签: python ssl salesforce ssl-certificate

使用simpleSalesforce运行Python代码时出现SSL错误。我正在笔记本电脑上运行它。因此,要通过工作代理服务器。有人告诉我代理服务器允许SSL通信。

错误为("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])",)

我已经从Salesforce获得了自签名证书。并将其放在两个位置。我不确定该使用哪个。

在命令“ python -mrequests.certs”的指导下,我将自签名证书放入输出cacert.pem中:

C:\Users\steej1\AppData\Local\Programs\Python\Python37\lib\runpy.py:125: RuntimeWarning: 'requests.certs' found in sys.modules after import of package 'requests', but prior to execution of 'requests.certs'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))
C:\Users\steej1\AppData\Local\Programs\Python\Python37\lib\site-packages\certifi\cacert.pem

并在命令python -c“ import ssl; print(ssl.get_default_verify_paths())”的指导下,我将自签名证书放入输出cert.pem文件中。

我可能必须阅读Python和openSSL并尝试在该级别编写一些代码来解决问题。 python simple_salesforce模块没有为我提供足够的信息来解决问题。

任何人都可以将一些简单的python代码指向我,这会麻烦我的python ssl配置。代码将确认我的python在哪里寻找证书。该代码将提供有关握手失败原因的更多信息。

这是我的代码:

from simple_salesforce import Salesforce

proxies = {
"http": "http://***.**.*.***:8080",
"https": "https://***.**.*.***:8080",
}

sf = Salesforce(password='**', username='**', security_token='**', proxies=proxies)

print ("Done building sf")

print ("Trying query")
query = 'SELECT * FROM Notice__c LIMIT 10'
result = sf.bulk.Notice__c.query(query)
print(result)

print ("End")
```

Here is the error.
=================
Done building sf
Trying query
Traceback (most recent call last):
  File "C:\Users\steej1\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\contrib\pyopenssl.py", line 453, in wrap_socket
    cnx.do_handshake()
  File "C:\Users\steej1\AppData\Local\Programs\Python\Python37\lib\site-packages\OpenSSL\SSL.py", line 1915, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "C:\Users\steej1\AppData\Local\Programs\Python\Python37\lib\site-packages\OpenSSL\SSL.py", line 1647, in _raise_ssl_error
    _raise_current_error()
  File "C:\Users\steej1\AppData\Local\Programs\Python\Python37\lib\site-packages\OpenSSL\_util.py", line 54, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]

0 个答案:

没有答案