Hey guys,
I'm trying to add a webhook to a project but it doesn't work. it always gives an Internal server error. I tried it locally but that worked. Also I tried just returning the request.json and manually changing the values to a dataframe. The site is connected to the web and it receives the json file.
The error is(flask): AttributeError: 'dict' object has no attribute 'to_html'
code from QC:
data = {
'symbol':self.aapl.Symbol.Value,
'time':self.Time,
'order Filled': random.randint(1000, 1001),
'order Sold': random.randint(1003, 1007),
'quantity': 1,
'profit': random.randint(1003, 1007)
}
if self.orders_dataframe is None:
self.orders_dataframe = pd.DataFrame(data=data,index=[0])
else:
self.orders_dataframe = self.orders_dataframe.append(data, ignore_index=True)
json_df = self.orders_dataframe.to_json(date_unit='ns')
self.Notify.Web('https://startfrom0sen.pythonanywhere.com/webhook', json_df)
code on PythonAnywhere:
from flask import Flask, request, Response, render_template, abort
import pandas as pd
from threading import Thread
import json
df = None
app = Flask(__name__,template_folder='templates')
counter = 0
ds = None
@app.route("/webhook", methods=["POST"])
def webhook():
global df
if request.method == 'POST':
counter=+ 1
print(request.json)
if df is None:
df = request.json
df = pd.read_json(df)
ds = df
df = df.iloc[:, [4,5,3,2,0,1]]
df['time'] = pd.to_datetime(df['time'])
else:
js_df = request.json
js_df = pd.read_json(js_df)
js_df = js_df.iloc[:, [4,5,3,2,0,1]]
js_df['time'] = pd.to_datetime(js_df['time'])
df = df.append(js_df)
return df
return "success", 200
else:
abort(400)
@app.route("/")
def main():
if df is None:
return str(counter)
else:
return str(counter), df.to_html()
if __name__ == '__main__':
app.run()
Nico Xenox
solved it by changing all of this:
to this:
Nico Xenox
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!