简体   繁体   English

AppEngine Paypal集成使用Python在localhost上提供SSLCertificateError

[英]AppEngine Paypal integration giving SSLCertificateError on localhost, using Python

i am integrating paypalrestsdk in my AppEngine project. 我正在将paypalrestsdk集成到我的AppEngine项目中。 When, using my local dev_appserver , i try to create a payment on the PayPal sandbox, i have the following error: 使用本地dev_appserver尝试在PayPal沙箱上创建付款时,出现以下错误:

SSLCertificateError: Invalid and/or missing SSL certificate for URL: https://api.sandbox.paypal.com/v1/oauth2/token

So, i have tried to provide the correct pem file, downloading it from here and setting up the correct ssl_option attribute: 因此,我尝试提供正确的pem文件,从此处下载它并设置正确的ssl_option属性:

# Setting up the correct path to the .pem file
cert = os.path.join(ROOT, 'certs/api.sandbox.paypal.com_SHA-2_01132018.pem')
logger.info("Using SSL certificate: %s", cert)
return Api(
    mode=get_paypal_environment(), # sandbox or live
    client_id=flask.current_app.config["PAYPAL_CLIENT_ID"],
    client_secret=flask.current_app.config["PAYPAL_CLIENT_SECRET"],
    ssl_options={"cert": cert}
)

Here there is the PayPalRestSDK documentation that gives details on how to provide certificate. 这里有PayPalRestSDK文档,其中提供了有关如何提供证书的详细信息。 I have double checked the path created is correct. 我仔细检查了创建的路径是否正确。

I have have found a bug report here that talks about a similar problem. 在这里找到了一个有关类似问题的错误报告。

Also, i have tried the solution suggested here and still does not work. 另外,我尝试了这里建议的解决方案,但仍然无法正常工作。

On a live instance, on appspot, this all works perfectly . 在一个在线实例上,在appspot上,这一切都可以完美地进行

Here's the relevant part of my requirements.txt: 这是我的requirements.txt的相关部分:

Flask==0.10.1
itsdangerous==0.24
paramiko==1.15.1
pycrypto==2.6.1
Flask-OAuthlib==0.9.1
google-api-python-client==1.4.0
paypalrestsdk==1.11.1
requests[security]==2.9.1

Is anyone having the same issue ? 有人遇到同样的问题吗?

OK, I believed I've solved this one, at least in my case, which I'll describe below. 好的,我相信至少在我的情况下,我已经解决了这一问题,下面将对此进行描述。

This seemed to be due to two issues: 这似乎是由于两个问题造成的:

Issue #1) PayPal is migrating to supporting only TLS 1.2, and has started by switching over the sandbox URLs, with the production URLs to come later. 问题#1)PayPal迁移至仅支持TLS 1.2,并且首先切换了沙箱URL,随后又推出了生产URL。 This explains why things are broken only when connecting from the sandbox, and why it used to work but doesn't now. 这就解释了为什么只有在从沙箱连接时才发生故障,以及为什么以前可以工作但现在却不行。 More on this here . 更多关于这里

Issue #2) My local install of Python didn't support TLS 1.2. 问题#2)我在本地安装的Python不支持TLS 1.2。 Here is an easy way to check: 这是一种简单的检查方法:

$ python
>>> import ssl
>>> print ssl._PROTOCOL_NAMES

If you don't see PROTOCOL_TLSv1_2 listed, this is definitely the issue. 如果未列出PROTOCOL_TLSv1_2 ,则肯定是问题所在。 In my case, I was using the builtin version on Python on Mac OS X 10.11, which had a pretty old version on OpenSSL built in. 就我而言,我在Mac OS X 10.11上的Python上使用了内置版本,而在OpenSSL上内置了一个相当旧的版本。

So how to fix it? 那么如何解决呢? Well, in my case, this worked pretty well (copied mostly from here ): 好吧,就我而言,这很好用(大部分是从这里复制的):

$ brew update
$ brew install openssl
$ brew link openssl --force 
$ brew install python --with-brewed-openssl
$ sudo ln -s /usr/local/Cellar/python/2.7.11/bin/python /usr/local/bin/python

Now if you run the test I listed above, you should see the 1.2 protocol listed. 现在,如果运行上面列出的测试,您应该会看到列出的1.2协议。

This should make everything work again, good luck! 这应该会使一切重新工作,祝您好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM