Command 'makemessages' error - django

I newbe in django and python. My project created under PyTools for Visual Studio 2013.
For localization I create 'locale' folder on manage.py level. And I try run the following command:
.\ClarisPyEnv\Scripts\python.exe manage.py makemessages -l he
And I got the error:
Exception in thread Thread-2377:
Traceback (most recent call last):
File "C:\Python34\lib\threading.py", line 921, in _bootstrap_inner
self.run()
File "C:\Python34\lib\threading.py", line 869, in run
self._target(*self._args, **self._kwargs)
File "C:\Python34\lib\subprocess.py", line 1170, in _readerthread
buffer.append(fh.read())
File "C:\Python34\lib\encodings\cp1255.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 766: char
acter maps to <undefined>
Traceback (most recent call last):
File "manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Alex\Documents\PythonProjects\ClarisPy\ClarisPy\ClarisPyEnv\lib
\site-packages\django\core\management\__init__.py", line 385, in execute_from_co
mmand_line
utility.execute()
File "C:\Users\Alex\Documents\PythonProjects\ClarisPy\ClarisPy\ClarisPyEnv\lib
\site-packages\django\core\management\__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Alex\Documents\PythonProjects\ClarisPy\ClarisPy\ClarisPyEnv\lib
\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Users\Alex\Documents\PythonProjects\ClarisPy\ClarisPy\ClarisPyEnv\lib
\site-packages\django\core\management\base.py", line 338, in execute
output = self.handle(*args, **options)
File "C:\Users\Alex\Documents\PythonProjects\ClarisPy\ClarisPy\ClarisPyEnv\lib
\site-packages\django\core\management\base.py", line 533, in handle
return self.handle_noargs(**options)
File "C:\Users\Alex\Documents\PythonProjects\ClarisPy\ClarisPy\ClarisPyEnv\lib
\site-packages\django\core\management\commands\makemessages.py", line 290, in ha
ndle_noargs
self.write_po_file(potfile, locale)
File "C:\Users\Alex\Documents\PythonProjects\ClarisPy\ClarisPy\ClarisPyEnv\lib
\site-packages\django\core\management\commands\makemessages.py", line 402, in wr
ite_po_file
msgs, errors, status = popen_wrapper(args)
File "C:\Users\Alex\Documents\PythonProjects\ClarisPy\ClarisPy\ClarisPyEnv\lib
\site-packages\django\core\management\utils.py", line 25, in popen_wrapper
output, errors = p.communicate()
File "C:\Python34\lib\subprocess.py", line 959, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
File "C:\Python34\lib\subprocess.py", line 1234, in _communicate
stdout = stdout[0]
IndexError: list index out of range
What this means ? Where a problem? help me please!
Thank
Alex

You dont need to specify unicode in pyhton 3.
Unicode is default.
from django.utils.translation import ugettext as _
_('חתול')
Is enof for the translation and encoding to work.

Related

Unable to restore DB after Database change to Postgres (Django)

I have migrated from SQLite to Postgres, but now I am unable to restore my data on Postgres, i am using Django db-backup package, it is giving me this error on dbrestore command
Traceback (most recent call last):
File "C:\Users\atifs\Documents\food_deliveryapp\fooddelivery\manage.py", line 22, in <module>
main()
File "C:\Users\atifs\Documents\food_deliveryapp\fooddelivery\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\dbbackup\management\commands\dbrestore.py", line 53, in handle
self._restore_backup()
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\dbbackup\management\commands\dbrestore.py", line 94, in _restore_backup
self.connector.restore_dump(input_file)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\dbbackup\db\base.py", line 92, in restore_dump
result = self._restore_dump(dump)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\dbbackup\db\postgresql.py", line 56, in _restore_dump
stdout, stderr = self.run_command(cmd, stdin=dump, env=self.restore_env)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\dbbackup\db\postgresql.py", line 21, in run_command
return super(PgDumpConnector, self).run_command(*args, **kwargs)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\dbbackup\db\base.py", line 150, in run_command
raise exceptions.CommandConnectorError(
dbbackup.db.exceptions.CommandConnectorError: Error running: psql --host=localhost --port=5432 --username=postgres --no-password --set ON_ERROR_STOP=on --single-transaction postgres
ERROR: syntax error at or near "AUTOINCREMENT"
LINE 1: ...S "auth_group" ("id" integer NOT NULL PRIMARY KEY AUTOINCREM...

DeserializationError when adding fixture on server (loaddata)

I am trying to add my data to database in my server. I use exactly the same JSON file in my local machine and it works. But when I do the same in server it gives me Deserialization Error.
The JSON file is so big that I can't show it here but I am sure there is no typo.
I did all migrations and database works - I can add object from admin dashboard. How can I solve this error?
The error I get:
Traceback (most recent call last):
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/serializers/json.py", line 69, in Deserializer
objects = json.loads(stream_or_string)
File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 72, in handle
self.loaddata(fixture_labels)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 114, in loaddata
self.load_label(fixture_label)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 172, in load_label
for obj in objects:
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/serializers/json.py", line 74, in Deserializer
raise DeserializationError() from exc
django.core.serializers.base.DeserializationError: Problem installing fixture '/home/testuser/myprojectt/myprojectt/articles/fixtures/article.json':
Checked the JSON again and again but it still working on local but the same error on server.
I am using Ubuntu on the server. And didn't have git-lfs installed. To solve this issue:
Install it with sudo apt-get install git-lfs.
Then run git lfs pull on project directory.
And then I managed to work with the JSON data as I wanted.

Django 2.0 haystack whoosh update index, rebuild index throw error

I am using django 2.0 with haystack+whoosh as a search. I configured as it is said in the documentation. Occurred problem is when i run ./manage.py rebuild_index it shows this error:
Traceback (most recent call last):
File "./manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/management/commands/rebuild_index.py", line 36, in handle
call_command('clear_index', **options)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/django/core/management/__init__.py", line 133, in call_command
', '.join(sorted(valid_options)),
TypeError: Unknown option(s) for clear_index command: batchsize, workers. Valid options are: commit, help, interactive, no_color, nocommit, noinput, pythonpath, settings, skip_checks, stderr, stdout, traceback, using, verbosity, version.
after that i tried update_index it shows me this error:
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 214, in handle self.update_backend(label, using)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 257, in update_backend
commit=self.commit, max_retries=self.max_retries)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 84, in do_update
backend.update(index, current_qs, commit=commit)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/backends/whoosh_backend.py", line 185, in update
doc = index.full_prepare(obj)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/indexes.py", line 208, in full_prepare
self.prepared_data = self.prepare(obj)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/indexes.py", line 199, in prepare
self.prepared_data[field.index_fieldname] = field.prepare(obj)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/fields.py", line 205, in prepare
return self.convert(super(CharField, self).prepare(obj))
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/fields.py", line 88, in prepare
values = self.resolve_attributes_lookup(current_objects, attrs)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/fields.py", line 131, in resolve_attributes_lookup
values.append(current_object())
TypeError: __call__() missing 1 required keyword-only argument: 'manager'
So has anyone faced this error? Is it related to django 2.0 because i managed it work well with django 1.11.
Your installed version of Haystack does not support Django 2.0. Support for Django 2.0 was added in Haystack 2.8, which was released in March 2018.

FileNotFoundError: [WinError 2] The system cannot find the file specified: 'manage.py' IN PYTHON/DJANGO

I have used below code in a thread running background.
os.chdir("MEDIA/" + str(email) + "/" + str(id) + "/")
os.system("rscript DataSet.R " + str(filename) + " >>logfile.log")
os.chdir(settings.BASE_DIR)
This Error comes sometimes whenever I run my server. I have no clue whats the issue here. Most of the time the code works. I have to use chdir to run my R scripts.
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\MEXSON~1\Desktop\PROJEC~1\TOX2020\MAINWE~1\TOX202~1\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
utility.execute()
File "C:\Users\MEXSON~1\Desktop\PROJEC~1\TOX2020\MAINWE~1\TOX202~1\lib\site-packages\django\core\management\__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\MEXSON~1\Desktop\PROJEC~1\TOX2020\MAINWE~1\TOX202~1\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\MEXSON~1\Desktop\PROJEC~1\TOX2020\MAINWE~1\TOX202~1\lib\site-packages\django\core\management\commands\runserver.py", line 62, in execute
super(Command, self).execute(*args, **options)
File "C:\Users\MEXSON~1\Desktop\PROJEC~1\TOX2020\MAINWE~1\TOX202~1\lib\site-packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "C:\Users\MEXSON~1\Desktop\PROJEC~1\TOX2020\MAINWE~1\TOX202~1\lib\site-packages\django\core\management\commands\runserver.py", line 101, in handle
self.run(**options)
File "C:\Users\MEXSON~1\Desktop\PROJEC~1\TOX2020\MAINWE~1\TOX202~1\lib\site-packages\django\core\management\commands\runserver.py", line 110, in run
autoreload.main(self.inner_run, None, options)
File "C:\Users\MEXSON~1\Desktop\PROJEC~1\TOX2020\MAINWE~1\TOX202~1\lib\site-packages\django\utils\autoreload.py", line 332, in main
reloader(wrapped_main_func, args, kwargs)
File "C:\Users\MEXSON~1\Desktop\PROJEC~1\TOX2020\MAINWE~1\TOX202~1\lib\site-packages\django\utils\autoreload.py", line 298, in python_reloader
reloader_thread()
File "C:\Users\MEXSON~1\Desktop\PROJEC~1\TOX2020\MAINWE~1\TOX202~1\lib\site-packages\django\utils\autoreload.py", line 276, in reloader_thread
change = fn()
File "C:\Users\MEXSON~1\Desktop\PROJEC~1\TOX2020\MAINWE~1\TOX202~1\lib\site-packages\django\utils\autoreload.py", line 206, in code_changed
stat = os.stat(filename)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'manage.py'
Just remove the below code from your script and it will perfectly workfine.
os.chdir(settings.BASE_DIR)
Or else,
Move your codes into a different script, and then import that script file.
Hope this helps.
You use 'runserver' to launch Django. It has an "autoreload" function that detects code changes and then restarts itself.
Since you change the directory of the process, Django is no longer in the project root, so the list of files it generates in django.utils.autoreload.gen_files does not compute.
The simple fix is to use subprocess and fork, then change directory in the child.

'NoneType' object is unsubscriptable during war file creation in Django-Jython

I am trying to generate a war file on my local machine, so as to deploy the Django application on the web server. I am using Django-Jython for the same purpose. I am using a MySQL database and have set the CLASSPATH variable as mentioned in the documentation. The name of my Django project is "gui" and it resides in C:\
I run the following command :
C:\gui> jython C:\gui\manage.py war --include-java-libs=C:\mysql-connector-java-5.1.16-bin.jar
And I get the following error :
Traceback (most recent call last): File "C:\gui\manage.py", line
10, in execute_from_command_line(sys.argv)
File
"C:\jython2.5.3\Lib\site-packages\django-1.4.3-py2.5.egg\django\core\management__init__.py",
line 443, in execute_from_command_line utility.execute()
File
"C:\jython2.5.3\Lib\site-packages\django-1.4.3-py2.5.egg\django\core\management__init__.py",
line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File
"C:\jython2.5.3\Lib\site-packages\django-1.4.3-py2.5.egg\django\core\management\base.py",
line 196, in run_from_argv
self.execute(*args, **options.dict)
File
"C:\jython2.5.3\Lib\site-packages\django-1.4.3-py2.5.egg\django\core\management\base.py",
line 217, in execute
translation.activate('en-us')
File
"C:\jython2.5.3\Lib\site-packages\django-1.4.3-py2.5.egg\django\core\management\base.py",
line 217, in execute
translation.activate('en-us')
File
"C:\jython2.5.3\Lib\site-packages\django-1.4.3-py2.5.egg\django\utils\translation__init__.py",
line 105, in activate
return _trans.activate(language)
File
"C:\jython2.5.3\Lib\site-packages\django-1.4.3-py2.5.egg\django\utils\translation\trans_real.py",
line 194, in activate
_active.value = translation(language)
File
"C:\jython2.5.3\Lib\site-packages\django-1.4.3-py2.5.egg\django\utils\translation\trans_real.py",
line 183, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File
"C:\jython2.5.3\Lib\site-packages\django-1.4.3-py2.5.egg\django\utils\translation\trans_real.py",
line 161, in _fetch
apppath = os.path.join(os.path.dirname(app.file), 'locale')
File "C:\jython2.5.3\Lib\ntpath.py", line 207, in dirname
return split(p)[0] File "C:\jython2.5.3\Lib\ntpath.py", line 164, in split
d, p = splitdrive(p) File "C:\jython2.5.3\Lib\ntpath.py", line 119, in splitdrive
if p[1:2] == ':': TypeError: 'NoneType' object is unsubscriptable