[英]How to debug a flask-restful api with pdb
I want to use pdb to step into some flask-restful code. 我想使用pdb进入一些烧瓶级代码。 I have an endpoint which returns a token.
我有一个返回令牌的端点。 I then use the token to access another endpoint which returns the required data.
然后,我使用令牌访问另一个端点,该端点返回所需的数据。 I would like to view the result of a database query.
我想查看数据库查询的结果。 How do I go about this?
我该怎么办?
I tried setting a breakpoint inside the class, but it does not get triggered when I send a request using the request library. 我尝试在类中设置一个断点,但是当我使用请求库发送请求时,不会触发该断点。
class FetchData(Resource):
@jwt_required
def get(self, args):
engine = create_engine('mysql+pymysql://')
conn = engine.connect()
tablemeta = MetaData()
tablemeta.reflect(bind=engine)
keydate = tablemeta.tables['KEYDATE']
coefficient = tablemeta.tables['COEFFICIENT']
vessel = tablemeta.tables['VESSEL']
update_dict = {}
s = select([coefficient])
s = s.where(coefficient.c.updated_date >= args["dt"])
rp = conn.execute(s)
result = []
for r in rp:
j = coefficient.join(vessel, r['idvessel'] == vessel.c.idvessel)
import pdb
pdb.set_trace()
vdm_id = select([vessel.c.vessel_id]).select_from(j)
vdm_id = conn.execute(vdm_id).scalar()
intermediate = []
intermediate.append({"vdm_id": vdm_id})
intermediate.append([dict(r)])
result.append(intermediate)
Or possibly there's another debugger I should be using? 也许我应该使用另一个调试器?
You should put your pdb
before the loop as it will never get to pdb
if you don't get any results. 您应该将
pdb
放在循环之前,因为如果没有任何结果,它将永远不会进入pdb
。
I have been using pdb
for the last few years in flask
without any problems. 最近几年,我一直在
flask
使用pdb
,没有任何问题。
只需使用print(随心所欲),这应该更快,更高效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.