Django和oracle TypeError:环境只能包含字符串

时间:2017-05-12 17:01:51

标签: django oracle

我有一个项目需要连接到oracle数据库

当我使用sqlite3时,它默认带有以下字符串:

Operation

应用程序没有问题,但是当我使用以下字符串连接oracle时:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

Django给了我以下错误:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.oracle',
        'NAME': 'DBARS_PROD',
        'USER': 'userhere',
        'PASSWORD': 'passhere',


        }
}

但是,如果我运行python命令manage.py test来测试连接,我会认为一切都是正确的:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\nbueno\Envs\nworksdev\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "C:\Users\nbueno\Envs\nworksdev\lib\site-packages\django\core\management\__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\nbueno\Envs\nworksdev\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\nbueno\Envs\nworksdev\lib\site-packages\django\core\management\commands\runserver.py", line 62, in execute
    super(Command, self).execute(*args, **options)
  File "C:\Users\nbueno\Envs\nworksdev\lib\site-packages\django\core\management\base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "C:\Users\nbueno\Envs\nworksdev\lib\site-packages\django\core\management\commands\runserver.py", line 101, in handle
    self.run(**options)
  File "C:\Users\nbueno\Envs\nworksdev\lib\site-packages\django\core\management\commands\runserver.py", line 110, in run
    autoreload.main(self.inner_run, None, options)
  File "C:\Users\nbueno\Envs\nworksdev\lib\site-packages\django\utils\autoreload.py", line 332, in main
    reloader(wrapped_main_func, args, kwargs)
  File "C:\Users\nbueno\Envs\nworksdev\lib\site-packages\django\utils\autoreload.py", line 303, in python_reloader
    exit_code = restart_with_reloader()
  File "C:\Users\nbueno\Envs\nworksdev\lib\site-packages\django\utils\autoreload.py", line 289, in restart_with_reloader
    exit_code = subprocess.call(args, env=new_environ)
  File "c:\python27\Lib\subprocess.py", line 523, in call
    return Popen(*popenargs, **kwargs).wait()
  File "c:\python27\Lib\subprocess.py", line 711, in __init__
    errread, errwrite)
  File "c:\python27\Lib\subprocess.py", line 959, in _execute_child
    startupinfo)
TypeError: environment can only contain strings

似乎当django查询oracle时,这会返回unicode而不是字符串。或者有人知道该怎么做吗?

1 个答案:

答案 0 :(得分:0)

我已经找到了解决方案,显然它是最后一个版本6.0b1中的驱动程序cx_oracle ...我遇到连接问题,我只是将其降级为5.2并且一切正常