Django paypalrestsdk错误 - OpenSSL.SSL.Error:[('SSL例程','tls_process_server_certificate','证书验证失败')]

时间:2018-05-09 05:27:12

标签: python django openssl paypal-rest-sdk

我在Django上编程并使用paypalrestsdk https://github.com/paypal/PayPal-Python-SDK

我收到此错误:

OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]

基本上我已经创建了BillingPlan(代码段https://gist.github.com/axilaris/2f9cf8f5c27a8a2095c5c9abf0dc4121),并显示:

Payment created successfully
2018-05-08 22:44:45,358 INFO Request[POST]: https://api.sandbox.paypal.com/v1/oauth2/token
2018-05-08 22:44:45,358 DEBUG Level: sandbox
2018-05-08 22:44:45,358 DEBUG Request: 
Headers: {'Authorization': 'Basic QVZ2cEhjMExScXFkcEFQZy1QZm1DU19jVlFNYTV1V3lsaXpBMXRpMDRjcm4tZF9jbWdyVFF5N0ZQOVZOcnlfdXRZN0IwZk91cEJSQlluVzM6RUpIcV9GLWwxbmNJLTY3YmFLYmREcWRJMVMtcGNOWkxwWjdvX29mcG10eGQ4ZlVRM2drQTFQR1J5ZzBOZER6VDY1dE5URlY2Y29lWDVVdHM=', 'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json', 'User-Agent': 'PayPalSDK/PayPal-Python-SDK 1.13.1 (requests 2.12.1; python 3.6.3; OpenSSL 1.0.2k 26 Jan 2017)', 'PayPal-Request-Id': 'b337cb66-b036-4a0a-9f70-aaa7011e73bb'}
Body: grant_type=client_credentials
2018-05-08 22:44:45,362 DEBUG Starting new HTTPS connection (1): api.sandbox.paypal.com
From cffi callback <function _verify_callback at 0x12972a268>:
Traceback (most recent call last):
File "/Users/some/Documents/project/somedotcom/somedotcomenv/lib/python3.6/site-packages/OpenSSL/SSL.py", line 313, in wrapper
_lib.X509_up_ref(x509)
...
File "/Users/some/Documents/project/somedotcom/somedotcomenv/lib/python3.6/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')]

可以在此处找到更完整的迹线细节: https://gist.github.com/axilaris/c181aaaa8261add4240fb2d042bd1ffc

如何解决此错误?感谢。

我的环境:

pyOpenSSL==17.5.0
paypalrestsdk==1.13.1 
Django==1.11.7
cryptography==2.1.3

1 个答案:

答案 0 :(得分:1)

PayPal的API require TLS 1.2我的猜测是你的底层安装的OpenSSL版本有点太旧而无法支持它。

使用以下命令确定您已安装的OpenSSL版本:

>>> import ssl
>>> print ssl.OPENSSL_VERSION
OpenSSL 1.0.2m  2 Nov 2017

如果您的任何内容低于1.0.1,则可能需要upgrade it using brew。根据我的经验,Mac OS X可以有相当陈旧的版本;我认为我的低至0.9.8。

一旦你升级了OpenSSL并确认在python shell中你看到了新版本,你可以通过运行代码来测试它。如果它仍然不起作用,我建议运行以下内容以获得有关连接运行状况的更细粒度的详细信息:

openssl s_client -showcerts -connect api.sandbox.paypal.com:443