Issue #767 resolved

Unicode Encode Error Using Payment Module

Jason Christa
created an issue

Here is the stack trace:

{{{ Traceback: File "C:\Users\JChrista\Projects\next_django\apps\django\core\handlers\" in get_response 92. response = callback(request, callback_args, callback_kwargs) File "C:\Users\JChrista\Projects\next_django\apps\django\views\decorators\" in _wrapped_view_func 44. response = view_func(request, *args, kwargs) File "C:\Users\JChrista\Projects\next_django\apps\satchmo\apps\payment\modules\authorizenet\" in confirm_info 10. return confirm.credit_confirm_info(request, config_get_group('PAYMENT_AUTHORIZENET')) File "C:\Users\JChrista\Projects\next_django\apps\django\views\decorators\" in _wrapped_view_func 44. response = view_func(request, args, **kwargs) File "C:\Users\JChrista\Projects\next_django\apps\satchmo\apps\payment\views\" in credit_confirm_info 216. controller.confirm() File "C:\Users\JChrista\Projects\next_django\apps\satchmo\apps\payment\views\" in confirm 82. if self.process(): File "C:\Users\JChrista\Projects\next_django\apps\satchmo\apps\payment\views\" in process 160. result = self.processor.process() File "C:\Users\JChrista\Projects\next_django\apps\satchmo\apps\payment\modules\" in process 113. return self.capture_payment(testing=testing) File "C:\Users\JChrista\Projects\next_django\apps\satchmo\apps\payment\modules\authorizenet\" in capture_payment 85. standard = self.get_standard_charge_data(amount=amount) File "C:\Users\JChrista\Projects\next_django\apps\satchmo\apps\payment\modules\authorizenet\" in get_standard_charge_data 310. part2 = "&" + urlencode(trans['custBillData']) File "C:\Python25\lib\" in urlencode 1250. v = quote_plus(str(v))

Exception Type: UnicodeEncodeError at /checkout/credit/confirm/ Exception Value: 'ascii' codec can't encode character u'\xe7' in position 10: ordinal not in range(128) }}}

This is causing a lot of grief for international customers.

Comments (6)

  1. Jason Christa reporter
    • changed resolution to fixed
    • changed status to closed
    • changed resolution to invalid
    • changed status to closed
    • changed milestone to 0.9
    • changed version to 1.0

    So I used the code from the above link and added a function to the end of it.

    def safe_urlencode(query, **kwargs):
        safe_query = dict()
        for key, value in query.iteritems():
            safe_query[key] = unicode_to_ascii(value)
        return urlencode(safe_query, **kwargs)

    Then for the customer data I did: safe_urlencode(trans['custBillData'])

  2. Jason Christa reporter

    using string.encode('latin-1') seems to fix the problem. I need to research to see if there is already a generic way to apply this to all strings sent to urlencode.

  3. Bob Waycott

    Okay, I've changed the import in payment.modules.authorizenet.processor from urllib.urlencode() to django.utils.http.urlencode(), rebuilt Satchmo & done some testing resubmitting the problematic data to Looks like Django's urlencode() does the trick, by adding in the step of calling Django's smart_str() func on each of the key/value pairs before passing off to urllib.urlencode() to ensure all data is Unicode before url-encoding.

    Sadly, I am still on SVN only right now & don't have a separate environment setup for the new hg based Satchmo. I'm a bit wary that a patch may somehow be off, but I'm going to attach one anyway so you guys can apply it, test it, and hopefully we can get this committed & no longer have this issue.

    Thanks, guys.

  4. Log in to comment