the code here is based on the practical code written by Liao Xuefeng"s python tutorial. It saves the Times during the user registration function test
. < H1 > 2. Code < / H1 >async def execute(sql,args,autocommit=True):
log(sql)
async with __pool.get() as conn:
if not autocommit: -sharp
await conn.begin()
try:
async with conn.cursor(aiomysql.DictCursor) as cur:
sql = sql.replace("?", "%s")
await cur.execute(sql, args)
affected = cur.rowcount -sharp sql
if not autocommit:
await conn.commit()
except BaseException as e:
print("e: ",e)
if not autocommit:
await conn.rollback()
raise
return affected
< H1 > 3. Error message < / H1 >
INFO:root:call with args: {"email": "dd@qq.com", "name": "dd", "passwd": "f23ab4e297b7b5632c7bd9c816281802ea5c51cf"}
INFO:root:SQL: select `id`, `email`, `passwd`, `admin`, `name`, `image`, `create_at` from `users` where email=?
INFO:root:rows returned: 0
INFO:root:SQL: insert into `users`(`email`, `passwd`, `admin`, `name`, `image`, `create_at`, `id`) values(?,?,?,?,?,?,?)
e: "builtin_function_or_method" object has no attribute "translate"
ERROR:aiohttp.server:Error handling request
Traceback (most recent call last):
File "D:\Python\awesome-python3-webapp\venv\lib\site-packages\aiohttp\web_protocol.py", line 385, in start
resp = await self._request_handler(request)
File "D:\Python\awesome-python3-webapp\venv\lib\site-packages\aiohttp\web_app.py", line 338, in _handle
resp = await handler(request)
File "D:\Python\awesome-python3-webapp\venv\lib\site-packages\aiohttp\web_middlewares.py", line 88, in impl
return await handler(request)
File "D:/Python/awesome-python3-webapp/www/app.py", line 38, in logger
return (await handler(request))
File "D:/Python/awesome-python3-webapp/www/app.py", line 58, in response
r = await handler(request)
File "D:\Python\awesome-python3-webapp\venv\lib\site-packages\aiohttp\web_urldispatcher.py", line 111, in handler_wrapper
result = await result
File "D:\Python\awesome-python3-webapp\www\coroweb.py", line 135, in __call__
r = await self._func(**kw)
File "C:\Python36\lib\asyncio\coroutines.py", line 225, in coro
res = yield from await_meth()
File "D:\Python\awesome-python3-webapp\www\handlers.py", line 150, in api_register_user
await user.save()
File "D:\Python\awesome-python3-webapp\www\orm.py", line 235, in save
rows = await execute(self.__insert__, args)
File "D:\Python\awesome-python3-webapp\www\orm.py", line 52, in execute
await cur.execute(sql, args)
File "D:\Python\awesome-python3-webapp\venv\lib\site-packages\aiomysql\cursors.py", line 238, in execute
query = query % self._escape_args(args, conn)
File "D:\Python\awesome-python3-webapp\venv\lib\site-packages\aiomysql\cursors.py", line 197, in _escape_args
return tuple(conn.escape(arg) for arg in args)
File "D:\Python\awesome-python3-webapp\venv\lib\site-packages\aiomysql\cursors.py", line 197, in <genexpr>
return tuple(conn.escape(arg) for arg in args)
File "D:\Python\awesome-python3-webapp\venv\lib\site-packages\aiomysql\connection.py", line 366, in escape
return escape_item(obj, self._charset)
File "D:\Python\awesome-python3-webapp\venv\lib\site-packages\pymysql\converters.py", line 27, in escape_item
val = encoder(val, mapping)
File "D:\Python\awesome-python3-webapp\venv\lib\site-packages\pymysql\converters.py", line 118, in escape_unicode
return u""%s"" % _escape_unicode(value)
File "D:\Python\awesome-python3-webapp\venv\lib\site-packages\pymysql\converters.py", line 73, in _escape_unicode
return value.translate(_escape_table)
AttributeError: "builtin_function_or_method" object has no attribute "translate"
come on, let"s have a look:)