You are not logged in.
Recently I have installed Arch linux instead of Ubuntu 15.04. I like it very much but unfortunately I've got an annoying error. I'm fond of web-development and for one of my projects I use Django and python 2 (I really need 2 version and not 3). Sometimes I need to duplicate server's db on my local PC. I do this with Django's ./manage.py dumpdata\loaddata. Using Ubuntu everything was fine but on Arch I get error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128). Could anyone help me to solve this problem? Thank you.
Some additional info:
1) As db server i use last pgSql. I checked encodings of databases and they are the same on Ubuntu and Arch (Utf-8)
2) On my Arch I have
➜ locale -a
C
en_US.utf8
POSIX
ru_RU.utf8
3) On server (which is Ubuntu 14.04)
➜ locale -a
C
C.UTF-8
en_US.utf8
POSIX
Last edited by m-den-i (2015-12-14 12:16:00)
Offline
Are you sure you are using Python 2? 'python' executable refers to python3, you may need to use
$ python2 manage.py loaddata fixture_fileOffline
Thank you for response, I'm defintely sure that I'm using python 2 (2.7.11) in my virtual environment.
Offline
Allright, try the following on both your local machine and development server and see what you get:
$ ./manage.py shell
>>> import sys
>>> sys.getdefaultencoding()Chances are 'ascii' and 'utf-8' encoding are mixed up between machines.
Offline
Unfortunately, it is not a problem. I've got encoding 'ascii' both on dev server and on local machine. The only difference is between python versions (2.7.6 on dev server and 2.7.11 on local machine).
Offline
Hmm, okay. How about we try to set the encoding manually. Try this on your Arch box
$ ./manage.py shell
>>> import sys
>>> reload(sys) # need to reload sys module to get access to setdefaultencoding() function
>>> sys.setdefaultencoding('utf-8') # we change the default encoding
>>> sys.getdefaultencoding()
'utf-8'
>>> from django.core.management import call_command
>>> call_command('loaddata', 'fixture_name') # where 'fixture_name' is name of you data dump fileIf this doesn't work I'm out of ideas. I am afraid this is as far as my 'python h4xor' skills go.
Offline
Yes, this solution works, thank you so much, man. ![]()
Offline
No problem. To make the solution permanent you can create a sitecustomize.py file and set encoding there. For example my virtualenv is located in '~/virtualenvs/python2.7-django'
$ vim ~/virtualenvs/python2.7-django/lib/python2.7/site-packages/sitecustomize.pyand put the following inside
import sys
sys.setdefaultencoding('utf-8')Afterward you can invoke the Django shell with './manage.py shell' and test if it works.
Offline