尝试与sqlalchemy sre_constants.error一起使用pymysql时出错:没有什么可重复的

时间:2014-02-18 12:20:50

标签: python sqlalchemy pymysql

我尝试使用pyqlql和sqlalchemy使用此代码:     

    from sqlalchemy import create_engine
    engine = create_engine("mysql+pymsql://root:@localhost/pydb")
    conn = engine.connect()
    

这里引发的异常是完整的堆栈跟踪:     

    Traceback (most recent call last):
      File "D:\Parser\dal__init__.py", line 3, in 
        engine = create_engine("mysql+pymsql://root:@localhost/pydb")
      File "C:\Python33\lib\site-packages\sqlalchemy-0.9.2-py3.3.egg\sqlalchemy\engine__init__.py", line 344, in create_engine
      File "C:\Python33\lib\site-packages\sqlalchemy-0.9.2-py3.3.egg\sqlalchemy\engine\strategies.py", line 48, in create
      File "C:\Python33\lib\site-packages\sqlalchemy-0.9.2-py3.3.egg\sqlalchemy\engine\url.py", line 163, in make_url
      File "C:\Python33\lib\site-packages\sqlalchemy-0.9.2-py3.3.egg\sqlalchemy\engine\url.py", line 183, in _parse_rfc1738_args
      File "C:\Python33\lib\re.py", line 214, in compile
        return _compile(pattern, flags)
      File "C:\Python33\lib\re.py", line 281, in _compile
        p = sre_compile.compile(pattern, flags)
      File "C:\Python33\lib\sre_compile.py", line 498, in compile
        code = _code(p, flags)
      File "C:\Python33\lib\sre_compile.py", line 483, in _code
        _compile(code, p.data, flags)
      File "C:\Python33\lib\sre_compile.py", line 75, in _compile
        elif _simple(av) and op is not REPEAT:
      File "C:\Python33\lib\sre_compile.py", line 362, in _simple
        raise error("nothing to repeat")
    sre_constants.error: nothing to repeat
    

2 个答案:

答案 0 :(得分:0)

从用户名后面的连接字符串中删除:。它应该是mysql+pymsql://root@localhost/pydb

答案 1 :(得分:0)

我对sqlalchemy 0.9.4和python3.3的工作URI是:

sqlalchemy.url = mysql+pymysql://user:password@host:port/database?charset=utf8&use_unicode=0

我使用pymysql而不是pymsql。