Python 3:属性错误:对象不可调用

时间:2018-07-22 01:13:11

标签: python

我正在尝试使用Python 3运行预测模型。这是代码行。

try:    
    with open("SalePriceModel_3.pkl","rb") as fp :
        loadedModel = pickle.load(fp,encoding="latin-1")
        sys.stdout.write('2')


    xCols = [u'MSSubClass', u'LotArea', u'OverallQual', u'OverallCond', u'YearBuilt',....]


    listVals = list()

    for colName in xCols :
        if colName in inData.keys():
            listVals.append(inData[colName])
        else:
            listVals.append(0)


    salePrice = loadedModel.predict(np.array(listVals).reshape(-1,33))


    return jsonify({'PredictedSalesPrice': salePrice[0]})
except Exception as  e:
    print(e)
    return e;   

有人可以指导如何解决这个问题吗?

这是完整的错误消息,包括追溯:

2'NoneType' object has no attribute 'keys'
[2018-07-21 22:23:23,394] ERROR in app: Exception on /api/getSalesPrice [GET]
Traceback (most recent call last):
  File "C:\Users\anant\Documents\Anaconda\lib\site-packages\flask\app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\anant\Documents\Anaconda\lib\site-packages\flask\app.py", line 1615, in full_dispatch_request
    return self.finalize_request(rv)
  File "C:\Users\anant\Documents\Anaconda\lib\site-packages\flask\app.py", line 1630, in finalize_request
    response = self.make_response(rv)
  File "C:\Users\anant\Documents\Anaconda\lib\site-packages\flask\app.py", line 1740, in make_response
    rv = self.response_class.force_type(rv, request.environ)
  File "C:\Users\anant\Documents\Anaconda\lib\site-packages\werkzeug\wrappers.py", line 921, in force_type
    response = BaseResponse(*_run_wsgi_app(response, environ))
  File "C:\Users\anant\Documents\Anaconda\lib\site-packages\werkzeug\test.py", line 923, in run_wsgi_app
    app_rv = app(environ, start_response)
TypeError: 'AttributeError' object is not callable
127.0.0.1 - - [21/Jul/2018 22:23:23] "GET /api/getSal

0 个答案:

没有答案