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

EncryptedCharField raises a traceback in the django admin #1

Open
erikcw opened this issue Jan 22, 2010 · 6 comments
Open

EncryptedCharField raises a traceback in the django admin #1

erikcw opened this issue Jan 22, 2010 · 6 comments

Comments

@erikcw
Copy link

erikcw commented Jan 22, 2010

Traceback (most recent call last):

 File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py", line 92, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py", line 490, in root
   return self.model_page(request, *url.split('/', 2))

 File "/usr/lib/python2.5/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
   response = view_func(request, *args, **kwargs)

 File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py", line 509, in model_page
   return admin_obj(request, rest_of_url)

 File "/usr/lib/python2.5/site-packages/django/contrib/admin/options.py", line 1098, in __call__
   return self.change_view(request, unquote(url))

 File "/usr/lib/python2.5/site-packages/django/db/transaction.py", line 240, in _commit_on_success
   res = func(*args, **kw)

 File "/usr/lib/python2.5/site-packages/django/contrib/admin/options.py", line 873, in change_view
   return self.render_change_form(request, context, change=True, obj=obj)

 File "/usr/lib/python2.5/site-packages/django/contrib/admin/options.py", line 590, in render_change_form
   ], context, context_instance=context_instance)

 File "/usr/lib/python2.5/site-packages/django/shortcuts/__init__.py", line 20, in render_to_response
   return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)

 File "/usr/lib/python2.5/site-packages/django/template/loader.py", line 108, in render_to_string
   return t.render(context_instance)

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 178, in render
   return self.nodelist.render(context)

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 779, in render
   bits.append(self.render_node(node, context))

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 792, in render_node
   return node.render(context)

 File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py", line 97, in render
   return compiled_parent.render(context)

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 178, in render
   return self.nodelist.render(context)

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 779, in render
   bits.append(self.render_node(node, context))

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 792, in render_node
   return node.render(context)

 File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py", line 97, in render
   return compiled_parent.render(context)

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 178, in render
   return self.nodelist.render(context)

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 779, in render
   bits.append(self.render_node(node, context))

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 792, in render_node
   return node.render(context)

 File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py", line 24, in render
   result = self.nodelist.render(context)

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 779, in render
   bits.append(self.render_node(node, context))

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 792, in render_node
   return node.render(context)

 File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py", line 155, in render
   nodelist.append(node.render(context))

 File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py", line 111, in render
   return self.template.render(context)

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 178, in render
   return self.nodelist.render(context)

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 779, in render
   bits.append(self.render_node(node, context))

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 792, in render_node
   return node.render(context)

 File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py", line 155, in render
   nodelist.append(node.render(context))

 File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py", line 155, in render
   nodelist.append(node.render(context))

 File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py", line 244, in render
   return self.nodelist_false.render(context)

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 779, in render
   bits.append(self.render_node(node, context))

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 792, in render_node
   return node.render(context)

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 831, in render
   return _render_value_in_context(output, context)

 File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 811, in _render_value_in_context
   value = force_unicode(value)

 File "/usr/lib/python2.5/site-packages/django/utils/encoding.py", line 92, in force_unicode
   raise DjangoUnicodeDecodeError(s, *e.args)

DjangoUnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-1: invalid data. You passed in <django.forms.forms.BoundField object at 0xb9e308c> (<class 'django.forms.forms.BoundField'>)
@erikcw
Copy link
Author

erikcw commented May 25, 2010

I don't think this issue is resolved. In fact, I just updated to the latest trunk, and now it is happening from the django shell as well.

"DjangoUnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-1: invalid data. You passed in '\xd0;\xb0\x86\xe5\xc1\xf3-\x8f\x7fj' (<type 'str'>)"

@erikcw
Copy link
Author

erikcw commented May 25, 2010

here is a traceback:

v='$AES$311ce7d6ca0980a12bce17dee2e2a42c'

In [142]: f.to_python(v)

DjangoUnicodeDecodeError Traceback (most recent call last)

/home/linx/linx/ in ()

/usr/lib/python2.5/site-packages/django_fields/fields.py in to_python(self, value)
59 self.cipher.decrypt(
60 binascii.a2b_hex(value[len(self.prefix):])
---> 61 ).split('\0')[0]
62 )
63 return value

/usr/lib/python2.5/site-packages/django/utils/encoding.pyc in force_unicode(s, encoding, strings_only, errors)
90 s = s.decode(encoding, errors)
91 except UnicodeDecodeError, e:
---> 92 raise DjangoUnicodeDecodeError(s, *e.args)
93 return s
94

DjangoUnicodeDecodeError: 'utf8' codec can't decode byte 0xb2 in position 5: unexpected code byte. You passed in '\x02\xcc\xabjY\xb2kt\xe5\x99\xe6\xac\xf8\xcfP\x9c' (<type 'str'>)

@svetlyak40wt
Copy link
Owner

Is this issue still actual?

@m-thielen
Copy link

Although this issue is old, I just had a UnicodeDecodeError (decoding a private key passphrase with no unicode chars).
Just in case anyone else stumbles upon this: updating django-fields to 0.2.2 solved it for me.

@pplante
Copy link

pplante commented Nov 11, 2013

This error still happens for me. My production/staging/development environments have different SECRET_KEY values in their configurations. When we dump data from production to staging/development the encrypted data is no longer usable (which is perfectly fine). However if we want to change this data we are forced to drop into a posgres shell to wipe out the values. If we do not wipe the data out, the app will error our with the traceback listed on this issue. It would be better if it just threw out the values, or raised a better error telling the developer that the data cannot be decrypted.

We're on version 0.2.2.

@ivanrvpereira
Copy link

One more to raise a better error

svetlyak40wt pushed a commit that referenced this issue Dec 31, 2016
Remove `ModelWithPrivateFields` and clean up test matrix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants