AppEngine Paypal集成,在本地主机上使用Python提供SSLCertificateError [英] AppEngine Paypal integration giving SSLCertificateError on localhost, using Python

查看:188
本文介绍了AppEngine Paypal集成,在本地主机上使用Python提供SSLCertificateError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AppEngine项目中整合了 paypalrestsdk 。当使用我的本地dev_appserver 时,我尝试在PayPal沙箱上创建付款,我遇到以下错误:

  SSLCertificateError:URL无效和/或缺少SSL证书:https://api.sandbox.paypal.com/v1/oauth2/token 

所以,我试图提供正确的pem文件,从这里并设置正确的 ssl_option 属性:

 #设置.pem文件的正确路径
cert = os.path.join(ROOT,'certs / api.sandbox.paypal (使用SSL证书:%s,cert)
返回Api(
mode = get_paypal_environment(),#sandbox或live
client_id = flask.current_app.config [PAYPAL_CLIENT_ID],
client_secret = flask.current_app.config [PAYPAL_CLIENT_SECRET],
ssl_options = {cert:cert}

这里有一个PayPalRestSDK文档,详细介绍了如何提供证书。



我发现了一个错误报告这里讲述了一个类似的问题。

此外,我已经尝试了解决方案建议

在实时实例上,在appspot上,这一切都很完美



以下是我的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

是否有人遇到同样的问题?

解决方案

确定,我相信我解决了这个问题,至少在我的情况下,我将在下面描述。



这似乎是由于两个问题:



问题#1)PayPal正在迁移到仅支持TLS 1.2,并开始通过切换沙盒网址,网址稍后再来。这就解释了为什么只有从沙盒连接时才会破坏事情,为什么事情会过去,但现在不行。有关此此处



问题#2)我本地安装的Python不支持TLS 1.2。这里有一个简单的方法来检查:

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

如果您没有看到 PROTOCOL_TLSv1_2 列出,这肯定是问题。就我而言,我在Mac OS X 10.11上使用Python的内置版本,在内置的OpenSSL上有一个相当旧的版本。



那么如何解决它?那么,在我的情况下,这工作得很好(主要从这里复制):

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

现在,如果您运行上面列出的测试,您应该看到列出的1.2协议。

再次祝你好运!


i am integrating paypalrestsdk in my AppEngine project. When, using my local dev_appserver, i try to create a payment on the PayPal sandbox, i have the following error:

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:

# 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. 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.

Here's the relevant part of my 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. 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. 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. 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.

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.

This should make everything work again, good luck!

这篇关于AppEngine Paypal集成,在本地主机上使用Python提供SSLCertificateError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆