Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.

启动应用没有数据最简单的解决方法(非常详细的讲解)(2023-2-14) #103

Open
myhhub opened this issue Feb 14, 2023 · 6 comments

Comments

@myhhub
Copy link

myhhub commented Feb 14, 2023

有问题可以参考:https://github.com/myhhub/InStock
抓取股票每日关键数据,计算股票各种指标,识别K线各种形态,内置多种选股策略,支持选股验证回测,支持自动交易,支持批量时间,运行高效

启动应用没有数据,原因就是程序调用的数据名称和密码与创建的数据库微服务的不一致。

按下面步骤操作:
1.大家查看common.py,找到程序调用的数据名称和密码等:
MYSQL_HOST = os.environ.get('MYSQL_HOST') if (os.environ.get('MYSQL_HOST') != None) else "mysqldb"//数据库服务主机名称
MYSQL_USER = os.environ.get('MYSQL_USER') if (os.environ.get('MYSQL_USER') != None) else "root"//数据库用户
MYSQL_PWD = os.environ.get('MYSQL_PWD') if (os.environ.get('MYSQL_PWD') != None) else "mysqldb"//数据库密码
MYSQL_DB = os.environ.get('MYSQL_DB') if (os.environ.get('MYSQL_DB') != None) else "stock_data"//数据库名称

2.删除错误的容器(删除微服务)
sudo docker rm -f mariadb stock mysqldb

3.创建数据库容器(启动数据库微服务)
sudo docker run --name mysqldb -v /data/mariadb/data:/var/lib/stock_data -e MYSQL_ROOT_PASSWORD=mysqldb -p 3316:3316 -d mariadb:latest
##说明:--name mysqldb(数据库服务主机名称mysqldb); /var/lib/stock_data(数据库名称stock_data);MYSQL_ROOT_PASSWORD=mysqldb(数据库密码mysqldb)。

4.创建stock容器(启动web微服务)
sudo docker run -itd --link=mysqldb --name stock -v /data/notebooks:/data/notebooks -p 8888:8888 -p 9999:9999 pythonstock/pythonstock:latest
##说明:--link=mysqldb(数据库服务主机名称mysqldb)。

5.启动任务抓取当天数据(可以选)
##进入stock容器
sudo docker exec -it stock bash
##手动运行任务
sh /data/stock/jobs/cron.daily/run_daily

6.浏览网站
注意:这时默认有个日期的过滤条件,如果这个日期的没有数据,当然显示空,清空过滤条件就能看到数据了。

@myhhub myhhub changed the title 启动应用没有数据最简单的解决方法(详细讲解,百分百解决)(2023-2-14) 启动应用没有数据最简单的解决方法(非常详细的讲解)(2023-2-14) Feb 14, 2023
@sodared
Copy link

sodared commented Mar 23, 2023

大佬问一下,mysql默认port是3306,你-p3316没问题吗

@janzxgit
Copy link

问题出在common.py的52行
这样改就对了
def conn():
try:
db = MySQLdb.connect(MYSQL_HOST, MYSQL_USER, MYSQL_PWD, MYSQL_DB, charset="utf8")
db.autocommit(on=True)
except Exception as e:
print("conn error :", e)
return None # return None or raise an error
return db.cursor()

@janzxgit
Copy link

def conn(): try: db = MySQLdb.connect(MYSQL_HOST, MYSQL_USER, MYSQL_PWD, MYSQL_DB, charset="utf8") db.autocommit(on=True) except Exception as e: print("conn error :", e) return None # return None or raise an error return db.cursor()

@janzxgit
Copy link

To fix this error, you need to move the db.autocommit(on=True) line inside the try block, after the database connection has been successfully established.
In this version of the function, the db.autocommit(on=True) line is executed only if the database connection is successfully established inside the try block. If an exception is raised, the function returns None or raises an error, indicating that the database connection failed.

@myhhub
Copy link
Author

myhhub commented Mar 28, 2023

大佬问一下,mysql默认port是3306,你-p3316没问题吗

没有问题,只要端口没占用就行,当然正常是不会占用。
还有问题可以参考:https://github.com/myhhub/InStock

@myhhub
Copy link
Author

myhhub commented Mar 28, 2023

To fix this error, you need to move the db.autocommit(on=True) line inside the try block, after the database connection has been successfully established. In this version of the function, the db.autocommit(on=True) line is executed only if the database connection is successfully established inside the try block. If an exception is raised, the function returns None or raises an error, indicating that the database connection failed.

有问题可以参考:https://github.com/myhhub/InStock
抓取股票每日关键数据,计算股票各种指标,识别K线各种形态,内置多种选股策略,支持选股验证回测,支持批量时间,运行高效

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants