aiomysql inserting operation failed !
emotions:
those days,i am using aiomysql(python3.5) to acess my database .But a 'strange' problem make me trouble more times.The problem is i can't insert data into my database table using aiomysql's cursor.execute(**) method. Fortunately,i sovled it after refering aiomysq's manual.
plateform:
1.ubuntu14.04
2.python3.5
error code:
import aiomysql
import asyncio
loop=asyncio.get_event_loop()
@asyncio.coroutine
def insert(loop):
pl=yield from aiomysql.create_pool(host='127.0.0.1',user='root',password='xxxxx',db='blog',loop=loop,port=3306)
with (yield from pl) as con:
cursor=yield from con.cursor()
yield from cursor.execute('insert into users(`user_name`,`email`,`password`) values("coder","1xxxxxb@gmail.com","FHEUIE@#@@##JNDJA")')
yield from cursor.close()
con.commit()
pl.close()
yield from pl.wait_closed()
loop.run_until_complete(insert(loop))
loop.run_forever()
I run the above code many times,but there is still no data in my database table.
solution:
After refering aiomysql's manual,I found 'aiomysql.commit' method is coroutine,that's a critical point.just rewrite 'con.commit()' to 'yield from con.commit()',the problem is sovled!
correct code:
import aiomysql
import asyncio
loop=asyncio.get_event_loop()
@asyncio.coroutine
def insert(loop):
pl=yield from aiomysql.create_pool(host='127.0.0.1',user='root',password='xxxxx',db='blog',loop=loop,port=3306)
with (yield from pl) as con:
cursor=yield from con.cursor()
yield from cursor.execute('insert into users(`user_name`,`email`,`password`) values("coder","1xxxxxb@gmail.com","FHEUIE@#@@##JNDJA")')
yield from cursor.close()
yield from con.commit()
pl.close()
yield from pl.wait_closed()
loop.run_until_complete(insert(loop))
loop.run_forever()
aiomysql inserting operation failed !的更多相关文章
- 安装 composer SSL operation failed with code 1
gavin@webdev:~> curl -sS https://getcomposer.org/installer | php Downloading... Download failed: ...
- vsftp关于"550 create directory operation failed"问题解决
前提: 昨天晚上配置好了vsftp, 但登陆后,除了浏览,什么也干不了.(如新建文件/文件夹, 删除文件, 重命名等都不可操作) 都是弹出 "550 create directory ope ...
- Error: ORA-16501: the Data Guard broker operation failed ORA-16625: cannot reach database
在备库上建配置文件 DGMGRL> create configuration 'sharkdbbork' as primary database is 'sharkdb' connect ide ...
- 550 Create directory operation failed
往Linux系统中上传文件时候,我们经常会使用FTP连接Linux,也经常会使用mkdir命令来创建目录.最近发现用mkdir创建目录时提示550 Create directory operation ...
- Linux虚拟主机通过FTP软件创建目录时提示550 Create Directory Operation Failed
更新时间:2017-06-07 13:26:11 分享: 问题描述 通过FTP软件连接Linux虚拟主机,在尝试创建新目录时,服务器返回错误提示:550 Create Directory Oper ...
- composer在update时提示file could not be downloaded: SSL operation failed with code 1. OpenSSL Error messages: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO
在开发的时候,需要把依赖的服务更新到最新,然后 手动composer update一下,提示如下: failed) Update failed (The "e "https://a ...
- xcode9上传app时报错iTunes Store operation failed 解决方案
问题 上传至itunes Connect时报了两个错: iTunes Store Operation Failed ERROR ITMS-xxxxx:"description length: ...
- 使用PHPMailer 中的报错解决 "Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:"
PHPMailer项目地址:https://github.com/PHPMailer/PHPMailer 项目中用到PHPMailer,使用过程中报错:"Connection failed. ...
- ftp删除目录和文件,目录下有文件删除提示【550 Remove directory operation failed.】
注意:目录下有文件,直接删除目录会失败,提示550 Remove directory operation failed. 必须先将目录下的文件都删除,才能删除目录 ftp命令行: ftp删除目 ...
随机推荐
- String | StringBuffer | StringBuilder 比较
2016的第一天,我决定写一篇博客来纪念这一天,希望一年好运吧. String|StringBuffer|StringBuilder这三者在我们学习JAVASE核心API的时候常常出来,而且大多数入门 ...
- 将服务器上的文件通过HttpWebRequest下载到本地
外网地址需要先映射. string path=""; path=@"http://222.92.71.116/P2Foundation/Images/logo.gif&q ...
- CSS中padding、margin两个重要属性的详细介绍及举例说明
http://www.x6x8.com/IT/199.html 本文将讲述HTML和CSS的关键—盒子模型(Box model). 理解Box model的关键便是margin和padding属性, ...
- self & this 上下文
对象:指向对象的首地址: 函数:代表了函数运行的主要上下文: 内部:在类的内部使用. self Within the body of a class method, self refers to th ...
- 2019全套Java视频 免费赠送
本人今年刚看完这套课程找到工作了 待遇还不错 现在送给大家 网盘链接:https://pan.baidu.com/s/1cEK6WoXS4F9SRgj1bZclqg提取码:bjl8希望对大家有用 一起 ...
- docker单主机网络
当你安装Docker时,它会自动创建三个网络.你可以使用以下docker network ls命令列出这些网络: [root@localhost ~]# docker network ls NETWO ...
- @Param注解在dao层的使用
有时在前台用ajax传过来许多参数,不知道在mybatis如何封装,就要用到@Param注解了,这时就不需要在映射文件写传入参数了,这种方法虽然比较取巧,但还是很实用的,如下图:
- iOS小技巧–用runtime 解决UIButton 重复点击问题
什么是这个问题 我们的按钮是点击一次响应一次, 即使频繁的点击也不会出问题, 可是某些场景下还偏偏就是会出问题. 通常是如何解决 我们通常会在按钮点击的时候设置这个按钮不可点击. 等待0.xS的延时后 ...
- skimage学习(一)
skimage即是Scikit-Image.基于python脚本语言开发的数字图片处理包 skimage包由许多的子模块组成,各个子模块提供不同的功能.主要子模块列表如下: data子模块学习 导入d ...
- mysql 备份 常用脚本
全备: innobackupex --defaults-file=/data/mysql3316/my3316.cnf --user=root --password=mysqlpass /data/b ...