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删除目 ...
随机推荐
- python+selenium之中类/函数/模块的简单介绍和方法调用
# coding=utf-8 class ClassA (object): string1 = "这是一个字符串." def instancefunc(self): print ( ...
- Java 基础案例
1.变量及基本数据类型 案例1:变量声明及赋值 //1.变量的声明 int a; //声明一个整型的变量a int b,c,d; //声明三个整型变量b,c,d //2.变量的初始化 int a = ...
- Codeforces 666E Forensic Examination SAM or SA+线段树合并
E. Forensic Examination http://codeforces.com/problemset/problem/666/E 题目大意:给模式串S以及m个特殊串,q个询问,询问S的子串 ...
- UVA 1623 Enther the Dragon 神龙喝水 (贪心)
贪心,每次遇到一个满水的湖要下暴雨的时候,就往前找之前最后一次满水之后的第一个没有下雨的且没有被用掉天day1. 因为如果不选这day1,那么之后的湖不一定能选上这一天.如果这一天后面还有没有下雨的天 ...
- C++ Stack 与String
// ConsoleApplication1.cpp : 此文件包含 "main" 函数.程序执行将在此处开始并结束. // #include "pch.h" ...
- python 搜集参数
def print_params(*params): print(params) print_params('Testing')print_params(1,2,3) #参数前的星号将所有值放置在同一 ...
- NSXMLParser
NSXMLParser的使用 2011-05-05 15:50:17| 分类: 解析|字号 订阅 NSXMLParser解析xml格式的数据 用法如下: 首先,NSXMLParser必须继续 ...
- Windows7设置局域网文件共享
首先要实现共享必须设置共享的机器与访问共享的机器在同一个工作组中. 右键桌面上的计算机图标=>属性 如果不一样的话,就需要点击[更改设置] 右键要共享的文件或者文件夹,点击[共享]打开共享标签: ...
- chrome浏览器 配置开机启动全屏(看板app模式设置)
chrome浏览器 配置开机启动全屏(看板app模式设置) 1.下载安装chrome浏览器. 2.建立一个chrome浏览器的快键方式,右键打开属性,如下图: 3.将目标选项卡的值修改为:&q ...
- linux的一些权限的操作 chmod
u ---属主 g ---用户组 o ---其他组 + ----赋予权限 - ----取消权限 = ----赋予权限并取消以前的权限 r = 4 //读 w =2 //写 x =1 //执 ...