我是python的新手,但它似乎是一种有趣的语言,所以我想继续学习它。
我一直在寻找有关这个主题的信息,但我似乎找不到合适的资料。 我已经安装了Python3.3,Pymysql,SQLAlchemy,(Pyramid)和MySQL。
使用pymysql连接到数据库可以正常使用此连接字符串。我使用pymysql,因为我想对数据库(gevent)进行异步调用,我需要SQLAlchemy,所以我可以做对象映射。
我目前正在使用pythonWin屏幕来测试我们是否可以连接到我们的数据库。
import pymysql
con = pymysql.connect(db='dbeerste', user='admin', passwd='admin', host='localhost', port=3306)
cur = con.cursor();
cur.execute("SELECT * FROM dbeerste.tabel1;")
结合这两个似乎不适合我。
import pymysql
import sqlalchemy
engine = sqlalchemy.create_engine("mysql+pymysql://admin:admin@127.0.0.1/dbeerste")
engine.connect()
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\base.py", line 1651, in connect
return self._connection_cls(self, **kwargs)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\base.py", line 59, in __init__
self.__connection = connection or engine.raw_connection()
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\base.py", line 1709, in raw_connection
return self.pool.unique_connection()
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\pool.py", line 220, in unique_connection
return _ConnectionFairy(self).checkout()
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\pool.py", line 425, in __init__
rec = self._connection_record = pool._do_get()
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\pool.py", line 777, in _do_get
con = self._create_connection()
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\pool.py", line 225, in _create_connection
return _ConnectionRecord(self)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\pool.py", line 322, in __init__
exec_once(self.connection, self)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\event.py", line 381, in exec_once
self(*args, **kw)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\event.py", line 398, in __call__
fn(*args, **kw)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\strategies.py", line 168, in first_connect
dialect.initialize(c)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\dialects\mysql\base.py", line 2052, in initialize
default.DefaultDialect.initialize(self, connection)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\default.py", line 172, in initialize
self._get_default_schema_name(connection)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\dialects\mysql\base.py", line 2019, in _get_default_schema_name
return connection.execute('SELECT DATABASE()').scalar()
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\base.py", line 664, in execute
params)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\base.py", line 808, in _execute_text
statement, parameters
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\base.py", line 871, in _execute_context
context)
File "C:\Python33\lib\site-packages\sqlalchemy-0.8.0b2-py3.3.egg\sqlalchemy\engine\default.py", line 322, in do_execute
cursor.execute(statement, parameters)
File "C:\Python33\lib\site-packages\pymysql3-0.4-py3.3.egg\pymysql\cursors.py", line 96, in execute
#query = query % conn.escape(args)
TypeError: unsupported operand type(s) for %: 'bytes' and 'tuple'
任何人都可以帮我解决这个问题,我会对任何回应感到高兴
ps:因为我对这种语言不熟悉所以我很乐意听到任何回复,如果有人有任何建议以另一种方式做到这一点,请输入您的意见。 我不是很多东西,只有Python3.3,异步调用和使用MVC。