error in accepting unicode in django-python 2.7.1o

0

Good morning for everyone. The error that comes up is the following:

At the moment I am trying to connect the database with django using mysql and the version of python 2.7.10 when using python manage.py and makemigrations in the end is as follows:

Microsoft Windows [Versión 10.0.10586]
(c) 2015 Microsoft Corporation. Todos los derechos reservados.

C:\Users\Aprendiz Sena\Desktop\jazmines3-master>manage.py makemigrations
'import sitecustomize' failed; use -v for traceback
Traceback (most recent call last):
  File "C:\Users\Aprendiz Sena\Desktop\jazmines3-master\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 303, in execute
    settings.INSTALLED_APPS
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 48, in __getattr__
    self._setup(name)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 44, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 92, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "C:\Users\Aprendiz Sena\Desktop\jazmines3-master\exequiales\settings.py", line 16, in <module>
    import sitecustomize
  File "C:\Python27\lib\site-packages\sitecustomize.py", line 2, in <module>
    sys.setdefaultencoding("UTF-8")
AttributeError: 'module' object has no attribute 'setdefaultencoding'

C:\Users\Aprendiz Sena\Desktop\jazmines3-master>
  

I do not know if it's because of the windows operating system, or I'm missing packages or   something similar in this case the packages installed are the following:

Django  1.8 2.0rc1
MySQL-python    1.2.5   1.2.5
Pillow  4.3.0   4.3.0
PyJWT   1.5.0   1.5.3
PyMySQL 0.7.11  0.7.11
asn1crypto  0.22.0  0.23.0
certifi 2017.4.17   2017.11.5
cffi    1.10.0  1.11.2
chardet 3.0.4   3.0.4
cryptography    2.0 2.1.4
django-bootstrap-form   3.3 3.3
django-contrib-comments 1.8.0   1.8.0
django-mysql-pymysql    0.1 0.1
enum34  1.1.6   1.1.6
idna    2.5 2.6
ipaddress   1.0.18  1.0.18
mysql   0.0.1   0.0.2
mysql-connector-python  8.0.5   8.0.5
numpy   1.13.3  1.13.3
olefile 0.44    0.44
pip 9.0.1   9.0.1
pyOpenSSL   17.1.0  17.5.0
pycparser   2.18    2.18
pytz    2017.2  2017.3
requests    2.18.1  2.18.4
setuptools  36.2.0  38.2.4
six 1.10.0  1.11.0
twilio  6.4.3   6.9.1
urllib3 1.21.1  1.22
wheel   0.30.0  0.30.0a0
  

and the database settings are like this:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'jazmines',
        'USER': 'root',
        'PASSWORD': 'root',
        'PORT': '3306',

    }
  

the sitecustomize.py to code in utf-8 is as follows:

import sys
sys.setdefaultencoding("UTF-8")

import io
io.open(filename, encoding='latin-1')
    
asked by hernan dario zapata villa 11.12.2017 в 16:05
source

1 answer

0

The problem is caused by setdefaultencoding() , python deletes the reference of this function after its initialization, so it has that error.

One possible solution is to use reload ():

import sys
# sys.setdefaultencoding() fue removido aqui
reload(sys)  # se recarga para habilitarlo devuelta
sys.setdefaultencoding('UTF-8')

However, this is not a sure thing to do: this is obviously a trick, since sys.setdefaultencoding() is intentionally removed from sys when Python starts. By re-activating it and changing the default encoding, you can decipher the code that depends on which ASCII is the default (this code can be from third parties, which would generally make fixing it impossible or dangerous).

    
answered by 12.12.2017 в 15:06