Connect Django with SAP Hana - django

I'm trying to connect django with a SAP Hana DB. I've installed a backend as described in github: https://github.com/kapilratnani/django_hana
and
configured the settings.py as specified:
'data_source': {
'ENGINE':'django.db.backends.django_hana',# I tried also 'django_hana' or 'hello' with the same results
'NAME': 'IOT',
'USER': 'ALEX',
'PASSWORD': 'PASSWORD',
'HOST': '186.47.255.17',
'PORT': '30015',
}
I'm getting a connection error, as if it is not recognizing the Engine: I get the same error if I type 'hello' in the engine. Here is the error:
Unhandled exception in thread started by <function wrapper at 0x7fc2a959f0c8>
Traceback (most recent call last):
File "/home/django/Env/singolar/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/django/Env/singolar/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "/home/django/Env/singolar/lib/python2.7/site-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/home/django/Env/singolar/lib/python2.7/site-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/django/Env/singolar/lib/python2.7/site-packages/django/core/checks/model_checks.py", line 28, in check_all_models
errors.extend(model.check(**kwargs))
File "/home/django/Env/singolar/lib/python2.7/site-packages/django/db/models/base.py", line 1172, in check
errors.extend(cls._check_long_column_names())
File "/home/django/Env/singolar/lib/python2.7/site-packages/django/db/models/base.py", line 1587, in _check_long_column_names
connection = connections[db]
File "/home/django/Env/singolar/lib/python2.7/site-packages/django/db/utils.py", line 212, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/django/Env/singolar/lib/python2.7/site-packages/django/db/utils.py", line 135, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django.db.backends.django_hana' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'postgresql', 'sqlite3'
Error was: No module named django_hana.base
Any ideas why it's not recognizing the Engine?

Found repository that supports Django 1.9 and resolves the error: github.com/mathebox/django_hana_pyhdb

Related

Django ValueError: Unable to configure handler 'file'

I have a hard time because I'm a django beginner.
Please share your wisdom in solving this problem.
python3 manage.py runserver
Problems arise when a project is executed.
I don't know the cause of the problem
settings.py
import os
from dotenv import load_dotenv
load_dotenv()
...
SECRET_KEY = os.getenv('SECRET_KEY')
DEBUG=os.getenv('DEBUG')
DATABASES = {
'default': {
'ENGINE': os.getenv('DB_ENGINE'),
'NAME': os.getenv('DB_NAME'),
'USER': os.getenv('DB_USER'),
'PASSWORD': os.getenv('DB_PASSWORD'),
'HOST': os.getenv('DB_HOST'),
'PORT': os.getenv('DB_PORT'),
}
}
...
and then I met this error message.
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/config.py", line 562, in configure
handler = self.configure_handler(handlers[name])
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/config.py", line 735, in configure_handler
result = factory(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/handlers.py", line 148, in __init__
BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/handlers.py", line 55, in __init__
logging.FileHandler.__init__(self, filename, mode, encoding, delay)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/__init__.py", line 1087, in __init__
StreamHandler.__init__(self, self._open())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/__init__.py", line 1116, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/logs/logfile'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/venv/lib/python3.7/site-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/venv/lib/python3.7/site-packages/django/utils/log.py", line 75, in configure_logging
logging_config_func(logging_settings)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/config.py", line 799, in dictConfig
dictConfigClass(config).configure()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/config.py", line 570, in configure
'%r' % name) from e
ValueError: Unable to configure handler 'file'
Is there something I'm missing?
What more information will be needed to solve this problem?
I'm sorry to send you a question with a little information.
thank you for watching
I'm waiting for answer

【Django×Google App Engine】No module named 'MySQLdb' when deploying

I'm setting GitHub source ↓
https://github.com/priyankavergadia/Django-Dialogflow-GoogleVisionAPI
But I have trouble in [Deploy the app to the App Engine standard environment] phase.
At a glance Deploying have been done well.But I'm trying to access webservice, so [502 Bad Gateway] appears.
At local environment(running python manage.py runserver), this program works well.
Please give me some advices.
My environment:
Windows10
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
django 2.2.4
MySQL second generation 5.7
mysql django
I serched and tried to:
install mysqlclient and uninstall PyMySQL
rewrite [import ~]part in various pattern...
description in Django setting.py below
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
# Install PyMySQL as mysqlclient/MySQLdb to use Django's mysqlclient adapter
# See https://docs.djangoproject.com/en/2.1/ref/databases/#mysql-db-api-drivers
# for more information
import MySQLdb as sql# noqa: 402
# [START db_setup]
if os.getenv('GAE_APPLICATION', None):
# Running on production App Engine, so connect to Google Cloud SQL using
# the unix socket at /cloudsql/<your-cloudsql-connection string>
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/michatbot-250809:us-central1:polls-instance2',
'USER': 'test',
'PASSWORD': '',
'NAME': 'polls',
}
}
else:
# Running locally so connect to either a local MySQL instance or connect to
# Cloud SQL via the proxy. To start the proxy via command line:
# $ cloud_sql_proxy -instances=[INSTANCE_CONNECTION_NAME]=tcp:3306
#
# See https://cloud.google.com/sql/docs/mysql-connect-proxy
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '127.0.0.1',
'PORT': '3306',
'NAME': 'polls',
'USER': 'test',
'PASSWORD': '',
}
}
# [END db_setup]
eroor log on Google App Engine below
textPayload: "Traceback (most recent call last):
File "/env/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/env/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 104, in init_process
super(ThreadWorker, self).init_process()
File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
self.load_wsgi()
File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
self.wsgi = self.app.wsgi()
File "/env/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/env/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
__import__(module)
File "/srv/main.py", line 1, in <module>
from mysite.wsgi import application
File "/srv/mysite/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/env/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/env/lib/python3.7/site-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/env/lib/python3.7/site-packages/django/conf/__init__.py", line 57, in __getattr__
self._setup(name)
File "/env/lib/python3.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/env/lib/python3.7/site-packages/django/conf/__init__.py", line 107, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/opt/python3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/srv/mysite/settings.py", line 82, in <module>
import MySQLdb as sql # noqa: 402
ModuleNotFoundError: No module named 'MySQLdb'"
There are two threads where the community figured out several ways to solve this error depending on your SO and software's versions. You can refer to these threads, second one, and also to this one that addresses discussion more about connecting MySQL in Python 3 on Windows.
Make sure to follow the documentation about Python 3.7 in the GAE Standard. Also, GAE has some specific support for using Django, I'd suggest going through the Django Support documentation and Django App example.

Django and oracle TypeError: environment can only contain strings

I have a project that I need to connect to an oracle database
When I use sqlite3 it brings by default with the following string:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
The application works without problems but when I connect with oracle with the following string:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'DBARS_PROD',
'USER': 'userhere',
'PASSWORD': 'passhere',
}
}
Django gives me the following error:
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
But if I run the python command manage.py test to test the connection I devuleve that everything is correct:
Creating test database for alias 'default'...
Creating test user...
System check identified no issues (0 silenced).
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Destroying test database for alias 'default'...
Destroying test user...
Destroying test database tables...
It seems that when django queries oracle this returns unicode and not strings. Or does anyone know what to do?
I already found the solution, apparently it was the driver cx_oracle in its last version 6.0b1 ... I had connection problems, I simply downgraded to 5.2 again and everything worked fine

How do I get south to work on jython2.7-django1.7?

I hoping that you can help me out. I currently have Django1.7 running on windows7/Java7/Jython2.7/Postgresql9.3/postgresql-9.3-1102.jdbc41.
For more details about django on jython and the database settings.
postgresql on jython-django
My settings are:
DATABASES = {
'default': {
'ENGINE': 'doj.db.backends.postgresql',
'NAME': 'lwc',
'USER': 'lwc',
'PASSWORD': 'lwc',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
My Question:
I am not able to install South by using pip. So, I just installed it manually from the source. Afterwards I do jython manage.py syncdb
I then get an error... Do you have any ideas how to resolve this error?
C:\Users\michmar3\workspace\lwc>jython manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\core\mana
gement\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\core\mana
gement\__init__.py", line 354, in execute
django.setup()
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\__init__.
py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\apps\regi
stry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\apps\conf
ig.py", line 197, in import_models
self.models_module = import_module(models_module_name)
File "C:\jython2.7b2\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\jython2.7b2\Lib\site-packages\south-1.0-py2.7.egg\south\models.py", l
ine 2, in <module>
from south.db import DEFAULT_DB_ALIAS
File "C:\jython2.7b2\Lib\site-packages\south-1.0-py2.7.egg\south\db\__init__.p
y", line 84, in <module>
db = dbs[DEFAULT_DB_ALIAS]
KeyError: 'default'
south will not work with django 1.7. http://south.aeracode.org/
The functionality that south used to provide has been directly merged into django with the 1.7 release.
See the django documentation for how to use the django migration support that replaces south. https://docs.djangoproject.com/en/1.7/topics/migrations/

django: django 1.2 on ubuntu lucid

I am trying to run django on my ubuntu lucid, but I get the following:
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 209, in execute
translation.activate('en-us')
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/__init__.py", line 66, in activate
return real_activate(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/functional.py", line 55, in _curried
return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/__init__.py", line 36, in delayed_loader
return getattr(trans, real_name)(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 193, in activate
_active[currentThread()] = translation(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 176, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/gruszczy/Programy/bozorth/../bozorth/notifications/__init__.py", line 2, in <module>
from django.db.models.signals import post_save
File "/usr/local/lib/python2.6/dist-packages/django/db/__init__.py", line 75, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/usr/local/lib/python2.6/dist-packages/django/db/utils.py", line 92, in __getitem__
conn = backend.DatabaseWrapper(db, alias)
File "/usr/local/lib/python2.6/dist-packages/django/db/backends/sqlite3/base.py", line 154, in __init__
super(DatabaseWrapper, self).__init__(*args, **kwargs)
TypeError: __init__() takes exactly 2 arguments (3 given)
I have created and empty project and only changed database settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'test.db3', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
Am I lacking some dependency?
try to define databases in Multiple database format