'builtin_function_or_method' object has no attribute 'translate'

< H1 > 1. Error AttributeError: "builtin_function_or_method" object has no attribute" translate" < / H1 > when executing await cur.execute (sql, args)

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:)

Mar.21,2021

d:Anaconda3libsite-packagespymysqlconnections.py in escape (self, obj, mapping)

810                 ret = "_binary" + ret
811             return ret

--> 812 return converters.escape_item (obj, self.charset, mapping=mapping)

813
814     def literal(self, obj):

d:Anaconda3libsite-packagespymysqlconverters.py in escape_item (val, charset, mapping)

 25         val = encoder(val, charset, mapping)
 26     else:

-> 27 val = encoder (val, mapping)

 28     return val
 29

d:Anaconda3libsite-packagespymysqlconverters.py in escape_unicode (value, mapping)

116
117 def escape_unicode(value, mapping=None):

--> 118 return u "% s'"% _ escape_unicode (value)

119
120 def escape_str(value, mapping=None):

d:Anaconda3libsite-packagespymysqlconverters.py in _ escape_unicode (value, mapping)

 71     Value should be unicode
 72     """

-> 73 return value.translate (_ escape_table)

 74
 75 if PY2:

AttributeError: 'builtin_function_or_method' object has no attribute' translate'

encountered the same problem. I'm sorry I haven't solved it yet. I searched for your problem, but I didn't find the answer. There's no way to know what's wrong with the code.


AttributeError: 'ValuesView' object has no attribute' translate'
ask for the answer.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea5a04-1d70.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea5a04-1d70.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?