Using sqlite3 within Google App Engine? - python

I am trying to deploy my Python + Django project to the Google App Engine. Right now it works fine on my local computer, but when I try running it as a project within the Google App Engine, I get the following error.
ImproperlyConfigured: 'django.db.backends.sqlite3' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2', 'sqlite3'
Error was: cannot import name utils
Here is the part of my settings.py file that specifies the sqlite3 database:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mydb.db', # 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.
}
}

Google App Engine requires that you use its own datastore, rather than sqlite or another database. There is a project that will allow you to use pretty much regular Django models on App Engine called django-nonrel. You can find more information about setting it up here: http://code.google.com/appengine/articles/django-nonrel.html

Related

Error was: No module named sqlite3

Settings for database are:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'dataBase', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'dataBase',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
and exception generates :
django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.db.backends.sqlite3' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: No module named sqlite3.base
Following django documentations https://docs.djangoproject.com/en/1.7/ref/contrib/gis/tutorial/
change the conf. like this if you are using sqlite (by the this is just for reference made changes according to your need like dbname and etc.)
DATABASES = {
'default': {
'NAME': os.path.join(BASE_DIR, 'yourdbname.sqlite'),
'ENGINE': 'django.db.backends.sqlite3',
}
}
this will create db by name "yourdbname" where your apps settings.py resides plus you can refer to this link i guess it will help you
If you use sqlite3 to store the data, you should change the conf file,here is an example , just change the db file location:
DATABASES = {
'default': {
'ENGINE': 'sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': './db.db', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'dataBase',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}

Is there a way to encrypt the MySQL password stored in Django?

I just started on a Django project and in the settings.py file of the project, the database section looks like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'blogengine', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'blogadmin',
'PASSWORD': 'blog#123',
'HOST': 'localhost', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '3306', # Set to empty string for default.
}
}
Is there any way in which I don't have to enter the password as plaintext but maybe enter it in some encrypted form?
Another thing you could do is not to store your password/token in your settings.py, it is a bad practice for security, instead of that, you should create an environment variable in the user that runs your app let's say:
export MYSQL_PASSWORD=1234
And read it from your django app as follows
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'blogengine', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'blogadmin',
'PASSWORD': os.getenv('MYSQL_PASSWORD'),
'HOST': 'localhost', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '3306', # Set to empty string for default.
}
}
You should do this for all your "sensible data" like EMAIL_HOST_PASSWORD, AWS tokens and secrets and that kind of stuff, this way you separate the configuration from the environment and you don't have to change those parameters in your testing server or local environment, you just have to ensure that your environment variables are the same but points to the correct location according to your environment.
There is no point in trying to protect that password.
Any token in that file that can be used to access the database can be used by anyone else to access the database. That's how shared secret security works. Replace the password by a randomly generated token, and you still have to communicate that token to settings.py, for example.
Your better bet is to restrict what computers can connect to your MySQL database using that username and password, adding an additional layer of security. Oh, and making sure no one can access settings.py by securing your webserver and source control systems properly.

Django testing MySQL permission

I am going through the Django tutorial and I've run into some trouble because I'm using MySQL as my database.
When I run
python manage.py test polls
I get
Creating test database for alias 'default'...
Got an error creating the test database: (1044, "Access denied for user 'USER123'#'%' to database 'test_USER123'")
Type 'yes' if you would like to try deleting the test database 'test_USER123', or 'no' to cancel:
This is my settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'USER123', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'USER123',
'PASSWORD': 'PASSWORD',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
I was wondering if anyone would explain to me what's wrong and what's going on. Thank you!

What is the pymysql3 equivalent of django.db.backends.mysql

I am running python33 and I have installed pymysql3 but what ENGINE do I need to specify in the Django settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'chris_test', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'some_user',
'PASSWORD': 'some password',
'HOST': 'some_host', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '3306', # Set to empty string for default.
}
}
Look at django-mysql-pymysql for more info. Specifically,
'ENGINE': 'mysql_pymysql',
That was not enough for me though. I had to use this answer . If you have a foo Django app, then in your `foo/init.py', add the following:
import pymysql
pymysql.install_as_MySQLdb()
Django already provides a MySQL backend. From looking at PyMySQL, it appears to be a general-purpose MySQL client. You can't arbitrarily use a different library in place of the existing Django backends; the APIs would be completely incompatible.
There is a project that appears to provide a Django backend that uses PyMySQL internally, but the author states that it is experimental, it has a total of 5 commits, and it hasn't been updated since 2012, so I wouldn't recommend trying to use it.

Django OperationalError at / (1045, "Access denied for user 'root'#'localhost' (using password: YES)")

Well, it refuses to work with root, but my settings are:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'stroiset74', # Or path to database file if using sqlite3.
'USER': 'stroiset74', # 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.
}
}
Interestingly, manage.py validate and manage.py syncdb still run without errors.
I faced the same problem, the issue was i had a local_settings.py with database configuration. changed the DB password.
I solved the problem on MY windows10 by searching the username globally in the project, and I found that both settings.py and views.py contains the username and password.
I only changed the configuration in settings.py, after changing the password in the views.py, the django worked.

Categories

Resources