Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save order fails with UnicodeEncodeError at /shop/checkout/ #212

Closed
wyzex opened this issue Oct 9, 2014 · 8 comments
Closed

Save order fails with UnicodeEncodeError at /shop/checkout/ #212

wyzex opened this issue Oct 9, 2014 · 8 comments

Comments

@wyzex
Copy link

wyzex commented Oct 9, 2014

Order save (last step on checkout) fails with UnicodeEncodeError
The string that could not be encoded/decoded was: Стоимость дост

it is the following string failed:

: checkout.py:40

msgid "Flat rate shipping"

This error is only occurred if localization is enabled (RU language).
Database is MySQL 5.1:0.2.17, charset is utf8_general_ci
Products, pages, variations are kept in Russian without issues.

LANGUAGE_CODE = "ru"

LANGUAGES = (
('ru', _('Russian')),
)

USE_I18N = True

Environment:

Request Method: POST
Request URL:

Django Version: 1.6.7
Python Version: 2.7.5
Installed Applications:
(u'mezzanine.boot',
u'django.contrib.auth',
u'django.contrib.contenttypes',
u'django.contrib.redirects',
u'django.contrib.sessions',
u'django.contrib.sites',
u'django.contrib.sitemaps',
u'django.contrib.staticfiles',
u'mhapp',
u'mhapp.mhtheme',
u'cartridge.shop',
u'mezzanine.conf',
u'mezzanine.core',
u'mezzanine.generic',
u'mezzanine.blog',
u'mezzanine.forms',
u'mezzanine.pages',
u'mezzanine.galleries',
u'mezzanine.accounts',
u'filebrowser_safe',
u'grappelli_safe',
u'django.contrib.admin',
u'django.contrib.comments')
Installed Middleware:
(u'django.contrib.sessions.middleware.SessionMiddleware',
u'django.middleware.locale.LocaleMiddleware',
u'django.contrib.auth.middleware.AuthenticationMiddleware',
u'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
u'django.middleware.common.CommonMiddleware',
u'django.middleware.csrf.CsrfViewMiddleware',
u'django.contrib.messages.middleware.MessageMiddleware',
u'cartridge.shop.middleware.ShopMiddleware',
u'mezzanine.core.request.CurrentRequestMiddleware',
u'mezzanine.core.middleware.TemplateForDeviceMiddleware',
u'mezzanine.core.middleware.TemplateForHostMiddleware',
u'mezzanine.core.middleware.AdminLoginInterfaceSelectorMiddleware',
u'mezzanine.core.middleware.SitePermissionMiddleware',
u'mezzanine.pages.middleware.PageMiddleware')

Traceback:
File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1.                 response = wrapped_callback(request, _callback_args, *_callback_kwargs)
    
    File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  2.     response = view_func(request, _args, *_kwargs)
    
    File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/cartridge/shop/views.py" in checkout_steps
  3.             order.setup(request)
    
    File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/cartridge/shop/models.py" in setup
  4.     self.save()  # We need an ID before we can add related items.
    
    File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/mezzanine/core/models.py" in save
  5.     super(SiteRelated, self).save(_args, *_kwargs)
    
    File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/django/db/models/base.py" in save
  6.                    force_update=force_update, update_fields=update_fields)
    
    File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/django/db/models/base.py" in save_base
  7.             self._save_parents(cls, using, update_fields)
    
    File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/django/db/models/base.py" in _save_parents
  8.         self._save_table(cls=parent, using=using, update_fields=update_fields)
    
    File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/django/db/models/base.py" in _save_table
  9.         result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
    
    File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/django/db/models/base.py" in _do_insert
  10.                            using=using, raw=raw)
    
    File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/django/db/models/manager.py" in _insert
  11.     return insert_query(self.model, objs, fields, **kwargs)
    
    File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/django/db/models/query.py" in insert_query
  12. return query.get_compiler(using=using).execute_sql(return_id)
    
    File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  13.         cursor.execute(sql, params)
    
    File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/django/db/backends/util.py" in execute
  14.         return super(CursorDebugWrapper, self).execute(sql, params)
    
    File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/django/db/backends/util.py" in execute
  15.             return self.cursor.execute(sql, params)
    
    File "/var/lib/openshift/52d044ace0b8cdfcd400021b/python/virtenv/lib/python2.7/site-packages/django/db/backends/mysql/base.py" in execute
  16.         return self.cursor.execute(query, args)
    
    File "/opt/rh/python27/root/usr/lib64/python2.7/site-packages/MySQLdb/cursors.py" in execute
  17.         query = query % db.literal(args)
    
    File "/opt/rh/python27/root/usr/lib64/python2.7/site-packages/MySQLdb/connections.py" in literal
  18.     return self.escape(o, self.encoders)
    
    File "/opt/rh/python27/root/usr/lib64/python2.7/site-packages/MySQLdb/connections.py" in string_literal
  19.             return db.string_literal(obj)
    

Exception Type: UnicodeEncodeError at /shop/checkout/
Exception Value: 'ascii' codec can't encode characters in position 0-8: ordinal not in range(128)

@stephenmcd
Copy link
Owner

Are you able to work out a fix? I can't reproduce the issue.

@jozefsukovsky
Copy link

It looks very similar to mine problem I wanted to report just now. It's caused by set_cookie in mezzanine/utils/views.py more specific in expires = datetime.strftime... because %a is used. My problem is caused when "remember me" is checked in checkout form and remember cookie has to be created.

when using locale, (in my case sk_SK) this is the ouput of expires:
št , 22-jan-2015 15:32:01 GMT

It's very strange because Thursday is the only day where "local" charater is used so this problem occurs only once a week.

@jozefsukovsky
Copy link

my traceback (it looks these are actually two similar problems):Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/Users/jsu/workspace/smartwallpaint_sk/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 67, in call
return self.application(environ, start_response)
File "/Users/jsu/workspace/smartwallpaint_sk/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 67, in call
return self.application(environ, start_response)
File "/Users/jsu/workspace/smartwallpaint_sk/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 213, in call
response_headers.append((str('Set-Cookie'), str(c.output(header=''))))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/Cookie.py", line 469, in output
return "%s %s" % ( header, self.OutputString(attrs) )
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/Cookie.py", line 517, in OutputString
return _semispacejoin(result)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 8: ordinal not in range(128)

@cozepup
Copy link

cozepup commented Dec 22, 2014

I also have this problem with RU locale, anybody know how to fix?

@wyzex
Copy link
Author

wyzex commented Dec 22, 2014

yes, the root cause is the localization of _("Flat rate shipping") in RU locale which is used in cartridge/shop/checkout.py. This (localized) string is set to request as parameter and doesn't work well.

I've just hot fixed it by removing localization - wyzex@531672b

I think Stephen can propose something permanent for this.

@stephenmcd
Copy link
Owner

Again, I can't reproduce this - here's a screenshot of the order completion page with RU as the language code: http://cl.ly/Z5FF

Again, I'd advise the correct fix being best provided by someone actually experiencing the issue.

@stephenmcd
Copy link
Owner

Closing this for now as I'm confident this isn't a Mezzanine/Cartridge bug. My best guess at this stage is an incorrect locale is defined for the actual Python environment. This might be misconfigured for Apache, supervisord, or any other number of components being used to run the actual application.

@ramirovazq
Copy link

Well, this issue was also happening for LANGUAGE_CODE = "es", but what stephenmcd mention (modify http://cl.ly/Z5FF), was really help form me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants