Unicode Error Django syncdb - python

I'm working on a project in Django python. It uses psycopg2 module, and PostgreSQL database, of course.
I've never had this problem before, I don't know if it's due to a .dump i made of the database, but when I try python manage.py syncdb it's throwing this error message:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in postition 177: ordinal not in range (128)
This is the first time this happens to me on this project, what puzzles me is that it wasn't throwing it before, btw the character it is referring is on a .json file, a string containing the hash of an image to be more specific.
On my settings.py file, I already have the # -*- coding: UTF-8 -*- string, any ideas about this?
Thanks in advance.
EDIT
Complete traceback of error:
(django1.5) F:\autanacenditel\backup\autana\comun>python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "F:\autanacenditel\django1.5\lib\site-packages\django\core\management\__i
nit__.py", line 453, in execute_from_command_line
utility.execute()
File "F:\autanacenditel\django1.5\lib\site-packages\django\core\management\__i
nit__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "F:\autanacenditel\django1.5\lib\site-packages\django\core\management\bas
e.py", line 229, in run_from_argv
stderr.write('%s: %s' % (e.__class__.__name__, e))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 177
: ordinal not in range(128)

Related

Error when pip installing simpletransformers

I am trying to install simpletransformers via pip, but it gives me the following error:
"ERROR: Exception:
Traceback (most recent call last):
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 180, in _main
status = self.run(options, args)
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 204, in wrapper
return func(self, options, args)
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 393, in run
installed = install_given_reqs(
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/req/__init__.py", line 77, in install_given_reqs
requirement.install(
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/req/req_install.py", line 782, in install
install_wheel(
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/operations/install/wheel.py", line 810, in install_wheel
_install_wheel(
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/operations/install/wheel.py", line 653, in _install_wheel
file.save()
File "/sw/arch/Debian10/EB_production/2021/software/Python/3.9.5-GCCcore-10.3.0/lib/python3.9/site-packages/pip/_internal/operations/install/wheel.py", line 419, in save
with open(self.dest_path, "wb") as dest:
UnicodeEncodeError: 'latin-1' codec can't encode character '\U0001f4f9' in position 75: ordinal not in range(256)
"
I am working on jupyterhub and have tried creating a conda environment with Python version 3.7 as suggested in other cases, but the problem was not solved.
Any tips are welcome!
The problem comes from the encodage.
I think these topics could help you.
Streamlit install fails on GitLab CI with UnicodeEncodeError
'ascii' codec can't encode character : ordinal not in range (128)
In general google your error message you'll find o lot of related post and maybe your answer.

Error running python runserver --nothreading -noreload

/home/saumen/.local/lib/python2.7/site-packages/django/core/management/__init__.py:316: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
if subcommand == 'runserver' and '--noreload' not in self.argv:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/saumen/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/home/saumen/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/saumen/.local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/saumen/.local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 61, in execute
super(Command, self).execute(*args, **options)
File "/home/saumen/.local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/saumen/.local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 86, in handle
'or address:port pair.' % options['addrport'])
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)
I am getting the error when I run python runserver --nothreading -noreload.what Can I do? I have installed mysqlclient and necessary python libraries.
First edit your answer and put code on line 86...
and error is happening because of UnicodeDecodeError:
This might work for you:(note: your_string is what you want to decode)
your_String.encode('ascii', 'ignore').decode('utf-8')
for more specific to your problem:
str(options['addrport']).encode('ascii', 'ignore').decode('utf-8')

Anaconda prompt giving an error on opening

I tried to install anaconda 2.7 on my new computer(running win10), but failed.
I had it installed on my old laptop (running win7), and I was using spyder happily. Now after the install, the Navigator refuses to open, and the anaconda prompt gives an error first hand when opening.
The error i am receiving:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda2\Scripts\conda-script.py", line 12, in
sys.exit(main())
File "C:\ProgramData\Anaconda2\lib\site-packages\conda\cli\main.py", line 145, in main
init_loggers()
File "C:\ProgramData\Anaconda2\lib\site-packages\conda\cli\main.py", line 56, in init_loggers
from ..gateways.logging import initialize_logging, set_verbosity
File "C:\ProgramData\Anaconda2\lib\site-packages\conda\gateways\logging.py", line 14, in
from ..common.io import attach_stderr_handler
File "C:\ProgramData\Anaconda2\lib\site-packages\conda\common\io.py", line 580, in
class time_recorder(ContextDecorator): # pragma: no cover
File "C:\ProgramData\Anaconda2\lib\site-packages\conda\common\io.py", line 581, in time_recorder
record_file = get_instrumentation_record_file()
File "C:\ProgramData\Anaconda2\lib\site-packages\conda\common\io.py", line 577, in get_instrumentation_record_file
return expand(os.environ.get("CONDA_INSTRUMENTATION_RECORD_FILE", default_record_file))
File "C:\ProgramData\Anaconda2\lib\site-packages\conda\common\path.py", line 49, in expand
return abspath(expanduser(expandvars(path))
enter code here
File "C:\ProgramData\Anaconda2\lib\ntpath.py", line 311, in expanduser
return userhome + path[i:]
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe1 in position 13: invalid continuation byte
I tried reinstalling anaconda completely, tried both 64 and 32 bit versions, tried miniconda, same error all the time.
Would really appreciate any help!
Seems to be related to non-utf-8 characters in your home directory.
See a similar issues for 'ascii' codec:
https://github.com/conda/conda/issues/1631
https://github.com/conda/conda/issues/1180
If you need to use Python 2 it is suggested to use Anaconda3 and create a Python 2 environment from that.

Can't instal Scrapy/Twisted

When I use "pip install" to install scrapy for Python on Windows, I request this feedback:
Exception:
Traceback (most recent call last):
File "c:\users\limin\appdata\local\programs\python\python36\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str
return s.decode(sys.__stdout__.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 30: invalid start byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\limin\appdata\local\programs\python\python36\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "c:\users\limin\appdata\local\programs\python\python36\lib\site-packages\pip\commands\install.py", line 342, in run
prefix=options.prefix_path,
File "c:\users\limin\appdata\local\programs\python\python36\lib\site-packages\pip\req\req_set.py", line 784, in install
**kwargs
File "c:\users\limin\appdata\local\programs\python\python36\lib\site-packages\pip\req\req_install.py", line 878, in install
spinner=spinner,
File "c:\users\limin\appdata\local\programs\python\python36\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
line = console_to_str(proc.stdout.readline())
File "c:\users\limin\appdata\local\programs\python\python36\lib\site-packages\pip\compat\__init__.py", line 75, in console_to_str
return s.decode('utf_8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 30: invalid start byte
I know it maybe a coding problem, but I don't know how to solve it.
Who can help me?
Thanks.
Scrapy runs on Python 2.7 and Python 3.3 or above (except on Windows where Python 3 is not supported yet).
Sorry to be the bearer of bad news. It's worth a chance to use Anaconda, which is also stated in the Scrapy docs, if you're particularly hell bent on using Python 3.6. Or if it's urgent, you can use Python 2.7 and pip install scrapy. From my experience, Python 2.7 works a lot better when in comes to Scrapy.

Python 2.7. Encoding into python and cmd

everyone.
I try to study django and python. But I have a problem. In my book there is such string:
django-admin.py startproject megaproject
When I try to execute this code, I get next message:
D:\Job\РАН\База Данных. Сомнология>django-admin.py startproject megaproject
Traceback (most recent call last):
File "C:\Python27\Scripts\django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
353, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 357,
in run_from_argv
self.stderr.write('%s: %s' % (e.__class__.__name__, e))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 8: ordinal
not in range(128)
This code work in english directory. But I have russian directory next type:
D:\Job\РАН\База Данных. Сомнология
This problem appear due differences encoding into python and cmd. And I cannot conform them. I try change coding into command line and into python. But I have no results. When I change encoding into cmd, I get bad string with strange symbols. When I add concretly encoding in title python-file, I have no result too.
The windows django can not work with Russian catalogs.

Categories

Resources