我在使用MYSQL作为数据库的Ubuntu 18.0上具有Flask应用程序,我确实有路由调用IBM Watson API来获取我的路由代码下方的预测
@app.route('/price', methods=['GET','POST'])
def price():
try:
PredictionItems = db.session.query(Prediction).all()
PriceItems = db.session.query(Price).filter_by(CreatedAt = datetime.date(datetime.now())).all()
except:
print(" Cant connect to database ")
form = PredicitForm(request.form)
if request.method == 'POST' and form.validate():
payload_scoring = {"fields":["Year", "Month", "Day", "Type"],"values":[[form.year.data,int(form.month.data),form.day.data,int(form.crop.data)]]}
response_scoring = requests.post('Ibm-instance', json=payload_scoring, headers= config.header)
print(json.loads(response_scoring.text))
response = json.loads(response_scoring.text)
try :
#get result from the response
month_num = int(response['values'][0][1])
month_i = "Month : " + calendar.month_name[month_num]
year = "Year : " + str(response['values'][0][0])
day = "Day : " + str(response['values'][0][2])
crop = int(response['values'][0][3])
if crop == 1 :
crop_txt = 'Red Irish Potato'
else :
crop_txt = 'White Irish Potato'
crop_txt_temp = "Crop : " + crop_txt
pre_prams = str(response['values'][0][4])
price_round = ("%.2f" % round(response['values'][0][5],2))
price = str("Predict Price : "+ price_round + " KSH (50KG)")
return render_template('price.html', form=form, month_i=month_i, day=day, year=year, price=price, crop_txt_temp=crop_txt_temp, PredictionItems = PredictionItems, PriceItems = PriceItems)
except KeyError :
print('Cant get response ')
return render_template('price.html', form = form, PredictionItems = PredictionItems, PriceItems = PriceItems)
return render_template('price.html', form = form, PredictionItems = PredictionItems, PriceItems = PriceItems)
我在此路由的服务器日志中遇到此错误,我不明白这是什么意思
{'trace': '1810d2lal1abw', 'errors': [{'code': 'expired_authorization_token', 'message': 'Expired authorization token.', 'target': {'type': 'header', 'name': 'Authorization'}}]}, referer: https://example.com/price