线程中未处理的异常已启动

时间:2015-11-20 19:15:05

标签: python django

当我运行项目时,我在第from MySQLdb.connections import Connection行的Mysqldb模块init.py中收到此错误。 这个错误是什么意思,我该如何修复它?安装了Python 3.4(64x),Django,Connector和Mysqldb。

def Connect(*args, **kwargs):
    from MySQLdb.connections import Connection
    return Connection(*args, **kwargs)

控制台日志:

    Unhandled exception in thread started by <pydev_monkey._NewThreadStartupWithTrace object at 0x0000000004D682B0>
Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm 4.5.4\helpers\pydev\pydev_monkey.py", line 427, in __call__
    return self.original_func(*self.args, **self.kwargs)
  File "C:\Python34\lib\site-packages\django\utils\autoreload.py", line 229, in wrapper
    fn(*args, **kwargs)
  File "C:\Python34\lib\site-packages\django\core\management\commands\runserver.py", line 114, in inner_run
    self.validate(display_num_errors=True)
  File "C:\Python34\lib\site-packages\django\core\management\base.py", line 469, in validate
    return self.check(app_configs=app_configs, display_num_errors=display_num_errors)
  File "C:\Python34\lib\site-packages\django\core\management\base.py", line 482, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\Python34\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Python34\lib\site-packages\django\core\checks\model_checks.py", line 28, in check_all_models
    errors.extend(model.check(**kwargs))
  File "C:\Python34\lib\site-packages\django\db\models\base.py", line 1205, in check
    errors.extend(cls._check_fields(**kwargs))
  File "C:\Python34\lib\site-packages\django\db\models\base.py", line 1282, in _check_fields
    errors.extend(field.check(**kwargs))
  File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line 934, in check
    errors = super(AutoField, self).check(**kwargs)
  File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line 207, in check
    errors.extend(self._check_backend_specific_checks(**kwargs))
  File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line 306, in _check_backend_specific_checks
    return connection.validation.check_field(self, **kwargs)
  File "C:\Python34\lib\site-packages\django\db\backends\mysql\validation.py", line 18, in check_field
    field_type = field.db_type(connection)
  File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line 614, in db_type
    return connection.data_types[self.get_internal_type()] % data
  File "C:\Python34\lib\site-packages\django\db\__init__.py", line 36, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "C:\Python34\lib\site-packages\django\utils\functional.py", line 59, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 196, in data_types
    if self.features.supports_microsecond_precision:
  File "C:\Python34\lib\site-packages\django\utils\functional.py", line 59, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Python34\lib\site-packages\django\db\backends\mysql\features.py", line 52, in supports_microsecond_precision
    return self.connection.mysql_version >= (5, 6, 4) and Database.version_info >= (1, 2, 5)
  File "C:\Python34\lib\site-packages\django\utils\functional.py", line 59, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 371, in mysql_version
    with self.temporary_connection():
  File "C:\Python34\lib\contextlib.py", line 59, in __enter__
    return next(self.gen)
  File "C:\Python34\lib\site-packages\django\db\backends\base\base.py", line 462, in temporary_connection
    cursor = self.cursor()
  File "C:\Python34\lib\site-packages\django\db\backends\base\base.py", line 162, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "C:\Python34\lib\site-packages\django\db\backends\base\base.py", line 135, in _cursor
    self.ensure_connection()
  File "C:\Python34\lib\site-packages\django\db\backends\base\base.py", line 130, in ensure_connection
    self.connect()
  File "C:\Python34\lib\site-packages\django\db\backends\base\base.py", line 119, in connect
    self.connection = self.get_new_connection(conn_params)
  File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 276, in get_new_connection
    conn = Database.connect(**conn_params)
  File "C:\Python34\lib\site-packages\MySQLdb\__init__.py", line 80, in Connect
    from MySQLdb.connections import Connection
  File "C:\Python34\lib\site-packages\MySQLdb\connections.py", line 36
    raise errorclass, errorvalue
                    ^
SyntaxError: invalid syntax

2 个答案:

答案 0 :(得分:2)

MySQLdb不支持Python 3。

但是还有其他客户可用。

您可以使用mysqlclient。这是MySQLdb的一个分支。

答案 1 :(得分:0)

您使用的MySQLdb软件包不是Python 3.它是一个Python 2软件包。在Python 2中,您可以在此堆栈跟踪的底部看到错误。在Python 3中它应该是:

raise errorclass(errorvalue)