Plaid API 快速入门项目报错 http://127.0.0.1:5000/get_access_token [英] Plaid API quickstart project error http://127.0.0.1:5000/get_access_token

查看:26
本文介绍了Plaid API 快速入门项目报错 http://127.0.0.1:5000/get_access_token的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开始使用 plaid API.我创建了我的帐户来获取 API 密钥,并且我有快速启动项目.我把我的密钥放在代码中(它们没有应用在下面的代码中),当我运行它时,我使用沙箱凭据.不幸的是,登录成功后,我在尝试接收访问令牌时总是收到相同的错误:

I am trying to get started with the plaid API. I created my account to get the API keys and I have the quickstart project. I put my keys in the code(they are not applied in the code below) and when I run it I use the sandbox credentials. Unfortunately after the log in succeeds I always receive the same error when trying to receive the access token:

HTTP500:服务器错误 - 服务器遇到意外情况阻止它完成请求. (XHR)POST -http://127.0.0.1:5000/get_access_token

HTTP500: SERVER ERROR - The server encountered an unexpected condition that prevented it from fulfilling the request.(XHR)POST - http://127.0.0.1:5000/get_access_token

代码如下:

import os
import datetime
import plaid
from flask import Flask
from flask import render_template
from flask import request
from flask import jsonify

app = Flask(__name__)


# Fill in your Plaid API keys - https://dashboard.plaid.com/account/keys
PLAID_CLIENT_ID = os.getenv('PLAID_CLIENT_ID')
PLAID_SECRET = os.getenv('PLAID_SECRET')
PLAID_PUBLIC_KEY = os.getenv('PLAID_PUBLIC_KEY')
# Use 'sandbox' to test with Plaid's Sandbox environment (username: 
user_good,
# password: pass_good)
# Use `development` to test with live users and credentials and `production`
# to go live
PLAID_ENV = os.getenv('PLAID_ENV', 'sandbox')


client = plaid.Client(client_id = PLAID_CLIENT_ID, secret=PLAID_SECRET,
                  public_key=PLAID_PUBLIC_KEY, environment=PLAID_ENV)

@app.route("/")
def index():
   return render_template('index.ejs', plaid_public_key=PLAID_PUBLIC_KEY, 
plaid_environment=PLAID_ENV)


access_token = None
public_token = None

@app.route("/get_access_token", methods=['POST'])
def get_access_token():
  global access_token
  public_token = request.form['public_token']
  exchange_response = client.Item.public_token.exchange(public_token)
  print ('public token: ' + public_token)
  print ('access token: ' + exchange_response['access_token'])
  print ('item ID: ' + exchange_response['item_id'])

  access_token = exchange_response['access_token']

  return jsonify(exchange_response)

@app.route("/accounts", methods=['GET'])
def accounts():
  global access_token
  accounts = client.Auth.get(access_token)
  return jsonify(accounts)

@app.route("/item", methods=['GET', 'POST'])
def item():
  global access_token
  item_response = client.Item.get(access_token)
  institution_response = client.Institutions.get_by_id(item_response['item']
['institution_id'])
  return jsonify({'item': item_response['item'], 'institution': 
institution_response['institution']})

@app.route("/transactions", methods=['GET', 'POST'])
def transactions():
  global access_token
  # Pull transactions for the last 30 days
  start_date = "{:%Y-%m-%d}".format(datetime.datetime.now() + 
datetime.timedelta(-30))
  end_date = "{:%Y-%m-%d}".format(datetime.datetime.now())

  try:
    response = client.Transactions.get(access_token, start_date, end_date)
    return jsonify(response)
  except plaid.errors.PlaidError as e:
    return jsonify({'error': {'error_code': e.code, 'error_message': 
str(e)}})

@app.route("/create_public_token", methods=['GET'])
def create_public_token():
  global access_token
  # Create a one-time use public_token for the Item. This public_token can 
be used to
  # initialize Link in update mode for the user.
  response = client.Item.public_token.create(access_token)
  return jsonify(response)

if __name__ == "__main__":
    app.run(port=os.getenv('PORT', 5000))

推荐答案

像这样更新你的代码PLAID_CLIENT_ID = 'client_id'PLAID_SECRET = '秘密'PLAID_PUBLIC_KEY = 'key'PLAID_ENV = '沙盒'

这篇关于Plaid API 快速入门项目报错 http://127.0.0.1:5000/get_access_token的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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