跑着跑着莫名其妙,某次请求发出之后就异常了。本来好好的,但是之后就全是这样的异常。
[2019-01-02 21:02:16,374] ERROR in app: Exception on /users [GET]
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 35, in reraise
raise value
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "controller.py", line 31, in get_users
user_num = dto.count_user()
File "/root/spider/web/dto.py", line 34, in count_user
cursor.execute("SELECT COUNT(*) FROM user")
File "/usr/local/lib/python3.5/dist-packages/pymysql/cursors.py", line 170, in execute
result = self._query(query)
File "/usr/local/lib/python3.5/dist-packages/pymysql/cursors.py", line 328, in _query
conn.query(q)
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 516, in query
self._execute_command(COMMAND.COM_QUERY, sql)
File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 750, in _execute_command
raise err.InterfaceError("(0, '')")
pymysql.err.InterfaceError: (0, '')
不懂是什么情况。
代码如下: 接口:
@app.route('/user/<uid>')
def get_user_photo(uid):
uid = int(uid)
offset = request.args.get('offset', type=int, default=0)
size = request.args.get('size', type=int, default=8)
photo_num = dao.count_photo(uid)
page_info = {}
if offset+size > photo_num:
size = photo_num - offset
page_info = {'has_next': False}
else:
page_info = {'has_next': True, 'next': offset+size}
result_data = dao.get_user_photo_info(uid, offset, size)
for photo in result_data:
photo['date'] = str(photo['date'])
result_data = dict(page_data=result_data)
result_data['page_info'] = page_info
result_data['count'] = photo_num
result_data['user_info'] = dao.get_user_info(uid)
return filtrate_headers(json.dumps(BaseResponse(200, result_data), default=lambda obj: obj.__dict__))
dao:
def count_user():
cursor.execute("SELECT COUNT(*) FROM user")
result = cursor.fetchall()
return result[0]['COUNT(*)']
def get_user_info(uid):
get_user_sql = "SELECT * FROM user WHERE uid=%d" %uid
cursor.execute(get_user_sql)
result = cursor.fetchall()
if len(result) == 1:
return result[0]
else:
return dict()
1
julyclyde 2019-01-03 17:25:36 +08:00
看数据库那边的日志
|