请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

为啥我得会报错呢?

import pymysql

from mysql.mysql.sql import conn

class mysql(object):
def init(self):
self.get_conn()

def get_conn(self):

    try:
       self.conn=pymysql.connect(
            host='hc-dev.ck420txi7os7.ap-southeast-1.rds.amazonaws.com',
            user='admin',
            passwd='******',
            db='guns',
            port=3306,
            charset='utf8'
        )

    except pymysql.Error as e:
        print('Error: %s' % e)
def close_conn(self):
    try:
        if self.conn:
            conn.close()
    except pymysql.Error as e:
        print('Error: %s' % e)

def get_one(self):
   # sql="SELECT * FROM t_user WHERE UUID= %s 'acd31223ae564a528f4cddb413c1e0bf'"
    sql="SELECT * FROM `t_promotion_bonus` WHERE UUID='a1b7a4c59a5e41eba7292094cba4c713'"

    cursor=self.conn.cursor()
    cursor.execute(sql,('test',))
    #print(cursor.rowcount)

    #rest=cursor.fetchone()
    rest=dict(zip([k[0]for k in cursor.description],cursor.fetchone()))
    print(rest)
    #print(rest['title'])
    cursor.close()
    self.close_conn()
    return rest

def add_one(self):
    sql=(
        "INSERT INTO `guns`.`t_market_bonus`(`UUID`, `SOURCE_UUID`, `PRODUCT_ORDER`, `AMOUNT`, `MY_M_LEVEL`, `MY_REFERRER_NUMBER`, `DIVIDEND_RATE`, `WHETHER_CONSOLATION_PRIZE`, `DIVIDEND_BASE`, `HIGHER_INTEREST_RATE`, `CREATETIME`) VALUES"
    "(%s, %s, %s, %s, %s, %s,%s, %s, %s, %s,%s);"
    )
    cursor=self.conn.cursor()
    cursor.execute(sql,('20433510a2b746f2bd073e9df163413b', 'NULL', 'NULL', '0.0291752304', '1', '10', '0.0500000000', '0', '1', '0.0500000000', '1587298331000'))
    self.conn.commit()
    cursor.close()
    self.close_conn()

def main(self):
    obj=mysql()
    #rest=obj.get_one()
    #print(rest['title'])
    obj.add_one()

if __name__=='__main__':
    main()

D:\python3\python.exe "D:/PyCharm Community Edition 2017.1.1/untitled/mysql/mysql/mysql.py"
Traceback (most recent call last):
File “D:/PyCharm Community Edition 2017.1.1/untitled/mysql/mysql/mysql.py”, line 3, in
from mysql.mysql.sql import conn
File “D:\PyCharm Community Edition 2017.1.1\untitled\mysql\mysql\mysql.py”, line 3, in
from mysql.mysql.sql import conn
ModuleNotFoundError: No module named ‘mysql.mysql’; ‘mysql’ is not a package

Process finished with exit code 1

正在回答

1回答

使用mysqlclient试试:
pip  install  mysqlclient

0 回复 有任何疑惑可以回复我~
  • 提问者 热爱编程学习 #1
    ERROR: Could not find a version that satisfies the requirement mysqlclient (from versions: none)
    ERROR: No matching distribution found for mysqlclient
    无法下载
    回复 有任何疑惑可以回复我~ 2020-09-05 15:35:05
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信