这是我的代码:
def test(request):
paypalrestsdk.configure({
"mode": "security-test-sandbox",
"client_id": "XXXXXXX-XXXX-XXXX-XXXX",
"client_secret": "XXXXXXX-XXXX-XXXX-XXXX" })
payment = paypalrestsdk.Payment({
"intent": "sale",
"payer": {
"payment_method": "credit_card",
"funding_instruments": [{
"credit_card": {
"type": "visa",
"number": "4417119669820331",
"expire_month": "11",
"expire_year": "2018",
"cvv2": "874",
"first_name": "Joe",
"last_name": "Shopper" }}]},
"transactions": [{
"item_list": {
"items": [{
"name": "item",
"sku": "item",
"price": "1.00",
"currency": "USD",
"quantity": 1 }]},
"amount": {
"total": "1.00",
"currency": "USD" },
"description": "This is the payment transaction description." }]})
if payment.create():
print("Payment created successfully")
else:
print(payment.error)
return render(request, "test.html")
执行命令 payment.create() 时出现错误:[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failed (_ssl.c:590) 。我正在使用 Mac 。请告诉我为什么?
答案1
我遇到了同样的问题,以下是我所发现的以及我如何修复的:
Apple 提供的 Python 版本与 openssl 的版本不符。您可以进入终端来测试您的版本:
python
>>> import ssl
>>> print ssl.OPENSSL_VERSION
OpenSSL 0.9.8zh 14 Jan 2016
以上是错误的版本。一种解决方法是安装新版本的 Python。最简单的方法可能是使用 home brew 作为描述在这里。
下面的内容类似于使用升级版 Python 时应该看到的内容。然后 paypalrestsdk 就可以正常工作了。
python
>>> import ssl
>>> print ssl.OPENSSL_VERSION
OpenSSL 1.0.2h 3 May 2016