I'm working on a project using django-python. This has "oaisearch" installed to retrieve the metadata from different websites and "django_elasticsearch_dsl" to index them. It was verified that "oaisearch" runs without problems.
The problem occurs when "python3 manage.py search_index --create -f" is run to start indexing.
The file "documents.py" that has the configuration of what you want to index is the following.
from elasticsearch_dsl import analyzer
from django_elasticsearch_dsl import DocType, Index
from oaisearch.models import Digital_Resources
digital_resources = Index('digital_resources')
digital_resources.settings(
number_of_shards=1,
number_of_replicas=0
)
html_strip = analyzer(
'html_strip',
tokenizer="standard",
filter=["standard", "lowercase", "stop", "snowball"],
char_filter=["html_strip"]
)
#digital_resources.doc_type
class Resources(DocType):
class Meta:
model = Digital_Resources
fields = [
#'oai_server',
'creator',
'title',
'subject',
'description',
'identifier',
]
The console failure message after executing the aforementioned command is as follows
Creating index 'digital_resources'
PUT http://localhost:9200/digital_resources [status:400 request:0.014s]
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.5/dist-packages/django_elasticsearch_dsl/management/commands/search_index.py", line 128, in handle
self._create(models, options)
File "/usr/local/lib/python3.5/dist-packages/django_elasticsearch_dsl/management/commands/search_index.py", line 84, in _create
index.create()
File "/usr/local/lib/python3.5/dist-packages/elasticsearch_dsl/index.py", line 203, in create
self.connection.indices.create(index=self._name, body=self.to_dict(), **kwargs)
File "/usr/local/lib/python3.5/dist-packages/elasticsearch/client/utils.py", line 76, in _wrapped
return func(*args, params=params, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/elasticsearch/client/indices.py", line 88, in create
params=params, body=body)
File "/usr/local/lib/python3.5/dist-packages/elasticsearch/transport.py", line 318, in perform_request
status, headers_response, data = connection.perform_request(method, url, params, body, headers=headers, ignore=ignore, timeout=timeout)
File "/usr/local/lib/python3.5/dist-packages/elasticsearch/connection/http_urllib3.py", line 186, in perform_request
self._raise_error(response.status, raw_data)
File "/usr/local/lib/python3.5/dist-packages/elasticsearch/connection/base.py", line 125, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', 'Root mapping definition has unsupported parameters: [doc : {properties={identifier={type=text}, creator={type=text}, subject={type=text}, description={type=text}, title={type=text}}}]')
What version of elasticsearch are you running? It looks like you are running elasticsearch 7.x which is not yet supported by your version of django_elasticsearch_dsl. Try looking for a newer version or using elasticsearch 6.x.
Related
We have done Django Upgrade from 1.11 to 2.2 version, we have almost completed, but there is one issue is present, when we run migrations by using the command python manage.py makemigrations
then we are getting following error.
but when we follow the below link issue is resolved.
Migrations error in django 2; AttributeError: 'str' object has no attribute 'decode'
but, I just want to know is there any other way to resolve this issue? I am feeling like there will be library to update which is causing this issue?
When we add manually as suggested in above link, its working fine, but we have docker integration to the project, then it will fail?
same issue is not happening with below django 2.2 and above 2.2.20 versions.
Error message is:
(env4) user2#SK385 pro % python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/core/management/commands/makemigrations.py", line 101, in handle
loader.check_consistent_history(connection)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/migrations/loader.py", line 283, in check_consistent_history
applied = recorder.applied_migrations()
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 73, in applied_migrations
if self.has_table():
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 56, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/ddtrace/contrib/django/db.py", line 65, in cursor
return DbApiTracedCursor(conn._datadog_original_cursor(), pin)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/base/base.py", line 256, in cursor
return self._cursor()
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/base/base.py", line 233, in _cursor
self.ensure_connection()
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/base/base.py", line 197, in connect
self.init_connection_state()
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 231, in init_connection_state
if self.features.is_sql_auto_is_null_enabled:
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/mysql/features.py", line 82, in is_sql_auto_is_null_enabled
cursor.execute('SELECT ##SQL_AUTO_IS_NULL')
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/ddtrace/contrib/dbapi/__init__.py", line 90, in execute
return self._trace_method(self.__wrapped__.execute, self._self_datadog_name, query, {}, query, *args, **kwargs)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/ddtrace/contrib/dbapi/__init__.py", line 44, in _trace_method
return method(*args, **kwargs)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/utils.py", line 103, in execute
sql = self.db.ops.last_executed_query(self.cursor, sql, params)
File "/Users/user2/Desktop/env4/lib/python3.7/site-packages/django/db/backends/mysql/operations.py", line 146, in last_executed_query
query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode'
user2
I think you're hitting this issue because you're using PyMySQL.
The issue was fixed in ticket 30380, but wasn't backported to Django 2.2.X because Django doesn't officially support PyMySQL.
Some options are:
Upgrade to Django 3.0.X+
Switch from PyMySQL to mysqlclient
patch your version of Django 2.2 (see the fix here)
I'm running tests with nose and would like to take advantage of the --failed flag. But as soon as I add it I get errors like these for user related models:
./manage.py test # works
./manage.py test --failed # fails
CommandError: One or more models did not validate:
vod.video: 'user' has a relation with model accounts.CustomUser, which has either not been installed or is abstract.
Packages:
Django==1.6.7
django-nose==1.3
nose==1.3.4
What am I doing wrong?
Update: I don't see the issue on my master branch. In the new branch I'm started to use the TenantTestCase class from django-tenant-schemas. May be the cause of the problem.
The traceback I get:
./manage.py test --failed --traceback
nosetests --failed --verbosity=1
Creating test database for alias 'default'...
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/dev/envs/py26/lib/python2.6/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/dev/envs/py26/lib/python2.6/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/dev/envs/py26/lib/python2.6/site-packages/django/core/management/commands/test.py", line 50, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/dev/envs/py26/lib/python2.6/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/dev/envs/py26/lib/python2.6/site-packages/django/core/management/commands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/home/dev/envs/py26/lib/python2.6/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/home/dev/envs/py26/lib/python2.6/site-packages/south/management/commands/test.py", line 8, in handle
super(Command, self).handle(*args, **kwargs)
File "/home/dev/envs/py26/lib/python2.6/site-packages/django/core/management/commands/test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/home/dev/envs/py26/lib/python2.6/site-packages/django_nose/runner.py", line 218, in run_tests
result = self.run_suite(nose_argv)
File "/home/dev/envs/py26/lib/python2.6/site-packages/django_nose/runner.py", line 165, in run_suite
addplugins=plugins_to_add)
File "/home/dev/envs/py26/lib/python2.6/site-packages/nose/core.py", line 121, in __init__
**extra_args)
File "/usr/lib/python2.6/unittest.py", line 817, in __init__
self.runTests()
File "/home/dev/envs/py26/lib/python2.6/site-packages/nose/core.py", line 207, in runTests
result = self.testRunner.run(self.test)
File "/home/dev/envs/py26/lib/python2.6/site-packages/nose/core.py", line 50, in run
wrapper = self.config.plugins.prepareTest(test)
File "/home/dev/envs/py26/lib/python2.6/site-packages/nose/plugins/manager.py", line 99, in __call__
return self.call(*arg, **kw)
File "/home/dev/envs/py26/lib/python2.6/site-packages/nose/plugins/manager.py", line 167, in simple
result = meth(*arg, **kw)
File "/home/dev/envs/py26/lib/python2.6/site-packages/django_nose/plugin.py", line 76, in prepareTest
self.old_names = self.runner.setup_databases()
File "/home/dev/envs/py26/lib/python2.6/site-packages/django_nose/runner.py", line 401, in setup_databases
return super(NoseTestSuiteRunner, self).setup_databases()
File "/home/dev/envs/py26/lib/python2.6/site-packages/django/test/runner.py", line 107, in setup_databases
return setup_databases(self.verbosity, self.interactive, **kwargs)
File "/home/dev/envs/py26/lib/python2.6/site-packages/django/test/runner.py", line 279, in setup_databases
verbosity, autoclobber=not interactive)
File "/home/dev/envs/py26/lib/python2.6/site-packages/django/db/backends/creation.py", line 339, in create_test_db
load_initial_data=False)
File "/home/dev/envs/py26/lib/python2.6/site-packages/django/core/management/__init__.py", line 159, in call_command
return klass.execute(*args, **defaults)
File "/home/dev/envs/py26/lib/python2.6/site-packages/django/core/management/base.py", line 284, in execute
self.validate()
File "/home/dev/envs/py26/lib/python2.6/site-packages/django/core/management/base.py", line 314, in validate
raise CommandError("One or more models did not validate:\n%s" % error_text)
django.core.management.base.CommandError: One or more models did not validate:
vod.video: 'user' has a relation with model accounts.CustomUser, which has either not been installed or is abstract.
I think it has to do with the custom user model. Check this out https://github.com/bernardopires/django-tenant-schemas/issues/237
I'm trying to run Selenium tests for a Django app on production server.
I am getting a syntax error on the finally: clause.
I don't see where the error is and all the tests ran fine in development.
Here is the code:
def activate_revision(self, user, revision):
self.title = revision.title
self.tagnames = revision.tagnames
self.body = self.rendered(revision.body)
self.active_revision = revision
# Try getting the previous revision
try:
prev_revision = NodeRevision.objects.get(node=self, revision=revision.revision-1)
update_activity = True
# Do not update the activity if only the tags are changed
if prev_revision.title == revision.title and prev_revision.body == revision.body \
and prev_revision.tagnames != revision.tagnames and not settings.UPDATE_LATEST_ACTIVITY_ON_TAG_EDIT:
update_activity = False
except NodeRevision.DoesNotExist:
update_activity = True
finally:
if update_activity:
self.update_last_activity(user)
self.save()
Here is the traceback:
$ python manage.py test forum
Traceback (most recent call last):
File "/usr/lib/python2.4/logging/__init__.py", line 731, in emit
msg = self.format(record)
File "/usr/lib/python2.4/logging/__init__.py", line 617, in format
return fmt.format(record)
File "/usr/lib/python2.4/logging/__init__.py", line 408, in format
s = self._fmt % record.__dict__
KeyError: 'funcName'
/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/db/models/fields/subclassing.py:80: DeprecationWarning: A Field class whose get_db_prep_lookup method hasn't been updated to take `connection` and `prepared` arguments.
new_class = super(SubfieldBase, cls).__new__(cls, name, bases, attrs)
/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/db/models/fields/subclassing.py:80: DeprecationWarning: A Field class whose get_db_prep_value method hasn't been updated to take `connection` and `prepared` arguments.
new_class = super(SubfieldBase, cls).__new__(cls, name, bases, attrs)
Traceback (most recent call last):
File "manage.py", line 13, in ?
execute_manager(settings)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/home/spirituality/lib/python2.7/South-0.7.3-py2.7.egg/south/management/commands/test.py", line 8, in handle
super(Command, self).handle(*args, **kwargs)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/core/management/commands/test.py", line 37, in handle
failures = test_runner.run_tests(test_labels)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/test/simple.py", line 358, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/test/simple.py", line 247, in build_suite
app = get_app(label)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/db/models/loading.py", line 129, in get_app
self._populate()
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/db/models/loading.py", line 61, in _populate
self.load_app(app_name, True)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/spirituality/webapps/spirituality/spirit_app/forum/models/__init__.py", line 2, in ?
from question import Question ,QuestionRevision, QuestionSubscription
File "/home/spirituality/webapps/spirituality/spirit_app/forum/models/question.py", line 1, in ?
from base import *
File "/home/spirituality/webapps/spirituality/spirit_app/forum/models/base.py", line 349, in ?
from node import Node, NodeRevision, NodeManager
File "/home/spirituality/webapps/spirituality/spirit_app/forum/models/node.py", line 383
finally:
^
SyntaxError: invalid syntax
First part of the traceback suggests that it's Python 2.4 on production. As per my comment above, the problem is that try..except..finally is only for Python 2.5 and newer. Upgrade production or rewrite the code to nest try..except inside an outer try..finally.
I am trying to apply tutorial http://docs.django-cms.org/en/2.1.3/getting_started/tutorial.html.
But I didn't succeed to perform the initial database setup
Why do I get this error when I run "python manage.py syncdb --all" ?
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 381, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 230, in execute
self.validate()
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "C:\Python27\lib\site-packages\django\core\management\validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 158, in get_app_errors
self._populate()
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 64, in _populate
self.load_app(app_name, True)
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\django_cms-2.2-py2.7.egg\cms\plugins\link\models.py", line 5, in <module>
class Link(CMSPlugin):
File "C:\Python27\lib\site-packages\django_cms-2.2-py2.7.egg\cms\plugins\link\models.py", line 11, in Link
url = models.URLField(_("link"), verify_exists=False, blank=True, null=True)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 1265, in __init__
CharField.__init__(self, verbose_name, name, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 614, in __init__
super(CharField, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'verify_exists'
The verify_exists parameter for UrlField was deprecated in the 1.3.1 security release and removed in the current Git master (1.5dev). https://docs.djangoproject.com/en/1.4/internals/deprecation/. This makes this version of django-cms incompatible with the current master. I would recommend using a stable Django release such as the latest 1.4 rather than master.
Django noob. Can you tell me what I am doing wrong here? I looked this up on google, and the closest issue I found was this and this -- but couldn't figure it out.
Is this a password issue? I have the mysql password on my settings.py
I appreciate your help.
j#ime:~/dotcloud$ dotcloud run jims.www python current/jims/manage.py syncdb
# python current/jims/manage.py syncdb
Traceback (most recent call last):
File "current/jims/manage.py", line 14, in <module>
execute_manager(settings)
File "/home/dotcloud/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/dotcloud/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/dotcloud/env/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/dotcloud/env/lib/python2.6/site-packages/django/core/management/base.py", line 219, in execute
self.validate()
File "/home/dotcloud/env/lib/python2.6/site-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/home/dotcloud/env/lib/python2.6/site-packages/django/core/management/validation.py", line 102, in get_validation_errors
connection.validation.validate_field(e, opts, f)
File "/home/dotcloud/env/lib/python2.6/site-packages/django/db/backends/mysql/validation.py", line 14, in validate_field
db_version = self.connection.get_server_version()
File "/home/dotcloud/env/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 338, in get_server_version
self.cursor()
File "/home/dotcloud/env/lib/python2.6/site-packages/django/db/backends/__init__.py", line 250, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/home/dotcloud/env/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 322, in _cursor
self.connection = Database.connect(**kwargs)
File "/home/dotcloud/env/lib/python2.6/site-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/home/dotcloud/env/lib/python2.6/site-packages/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'jims'#'ip-10-68-47-216.ec2.internal' (using password: YES)")
Abort.