我有一个flask应用程序(python3.7),该应用程序调用一个功能并以纯文本格式返回库存数据。 脚本在自己的.py中运行时效果很好(从stock.screener import Screener >> stock_list = Screener(filters = filters,order ='price',table ='Overview')。 在flask应用程序中,但是出现以下错误: 线程“ Thread-2”中没有当前事件循环。 **在这里尝试了所有方法以使其正常工作-异步,仅在杂草中进行驯化
尝试过异步处理,治疗。.我只是被杂草所吸引-预先感谢!
from flask import Flask
from stock.screener import Screener
app = Flask(__name__)
@app.route('/')
def check_server():
return "Server is Running!"
@app.route('/test')
def run_screener():
try:
r = Screener(filters=['cap_nano','sh_avgvol_o200','sh_price_u10','sh_relvol_o2','sh_short_u30','ta_rsi_os40'], order='price', table='Overview')
return r
except Exception as e:
return str(e), 500
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
预期结果:
No. | Ticker | Company | Sector | Industry | Country | Market Cap | P/E | Price | Change | Volume
--- | ------ | --------------------------------- | --------------- | ----------------------------------- | -------------- | ---------- | ---- | ----- | ------- | ----------
1 | OHGI | One Horizon Group, Inc. | Technology | Application Software | United Kingdom | 1.44M | - | 0.02 | -8.57% | 660,189
2 | LODE | Comstock Mining Inc. | Basic Materials | Gold | USA | 11.57M | - | 0.13 | -9.29% | 4,668,153
3 | VIVE | Viveve Medical, Inc. | Healthcare | Medical Appliances & Equipment | USA | 6.58M | - | 0.13 | -8.47% | 6,520,180
4 | UPL | Ultra Petroleum Corp. | Basic Materials | Independent Oil & Gas | USA | 26.65M | 0.34 | 0.14 | -21.10% | 14,748,106