使用python调用函数会产生未定义的错误

时间:2019-01-26 19:15:09

标签: python

我需要为PORTFOLIO分配一个NOTE。 我已经用Python编写了代码以登录到LendingClub,并且工作正常(我能够获得余额)。 当我调用assign_to_portfolio()函数时,出现错误“ NameError:未定义名称'assign_to_portfolio'”

但是我已经运行了命令“ import lendingclub”,并且assign_to_portfolio()是 init .py的一部分,如https://github.com/jgillick/LendingClub/blob/master/lendingclub/init.py中所示。 我在做什么错了?

lc_InvestorId = "xxxxx"
lc_apikey = "xxxxxxxxxxxxxxxx"
url = "https://api.lendingclub.com/api/investor/v1/accounts/" + lc_InvestorId + "/availablecash"

import requests
import argparse
import sys
import glob
from lendingclub import LendingClub
import lendingclub


payload = ""
headers = {
    'ContentType': "application/json",
    'Accept': "application/json",
    'Authorization': lc_apikey,
    'X-LC-Application-Key': "null"
    }

response = requests.request("GET", url, data=payload, headers=headers)

print(response.text)

assign_to_portfolio()

1 个答案:

答案 0 :(得分:1)

必须在您的assign_to_portfolio()实例上调用

LendingClub

根据我的理解,阅读LendignClub类的自述文件和文档字符串:

通过将电子邮件和密码作为参数传递给LendingClub,然后调用.authenticate()或在默认实例上调用.authenticate()并将它们插入控制台中,从而使用电子邮件和密码“连接”帐户LendingClub中的。然后,您可以使用.authenticate() ed实例执行操作。

要使所有功能正常工作,建议您按照README中的示例进行操作(它们是否提供模拟帐户?),然后添加您想要的内容。

阅读自述文件后,我必须说,我对问题中的代码了解得较少,您确定您没有使事情变得过于复杂吗? (就像使用简单的python包混合使用API​​来模拟浏览器一样)