Incorrect Padding error

Hi! I’m relatively new to Django. Using Django 3.1.2 in Python 3.6.9 to build an app. Using a form from class to create an object, but when I click submit, I get the following and I’m not sure what ‘incorrect padding’ means. The object I’m attempt to create includes a CharField and TextField and the other form fields are not filled out (including an urlfields, emailfields, an imagefield and some datefields) …
Any help would be appreciated.:


Request Method: POST
Request URL:

Django Version: 3.1.2
Python Version: 3.6.9
Installed Applications:
Installed Middleware:

Traceback (most recent call last):
  File "/home/anteo/.envs/prisonerSolidarity/lib/python3.6/site-packages/django/core/handlers/", line 47, in inner
    response = get_response(request)
  File "/home/anteo/.envs/prisonerSolidarity/lib/python3.6/site-packages/django/core/handlers/", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/anteo/.envs/prisonerSolidarity/lib/python3.6/site-packages/django/views/generic/", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/anteo/.envs/prisonerSolidarity/lib/python3.6/site-packages/django/views/generic/", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/anteo/.envs/prisonerSolidarity/lib/python3.6/site-packages/django/views/generic/", line 172, in post
    return super().post(request, *args, **kwargs)
  File "/home/anteo/.envs/prisonerSolidarity/lib/python3.6/site-packages/django/views/generic/", line 141, in post
    if form.is_valid():
  File "/home/anteo/.envs/prisonerSolidarity/lib/python3.6/site-packages/django/forms/", line 177, in is_valid
    return self.is_bound and not self.errors
  File "/home/anteo/.envs/prisonerSolidarity/lib/python3.6/site-packages/django/forms/", line 172, in errors
  File "/home/anteo/.envs/prisonerSolidarity/lib/python3.6/site-packages/django/forms/", line 376, in full_clean
  File "/home/anteo/.envs/prisonerSolidarity/lib/python3.6/site-packages/django/forms/", line 405, in _post_clean
    self.instance.full_clean(exclude=exclude, validate_unique=False)
  File "/home/anteo/.envs/prisonerSolidarity/lib/python3.6/site-packages/django/db/models/", line 1209, in full_clean
  File "/home/anteo/.envs/prisonerSolidarity/lib/python3.6/site-packages/django/db/models/", line 1251, in clean_fields
    setattr(self, f.attname, f.clean(raw_value, self))
  File "/home/anteo/.envs/prisonerSolidarity/lib/python3.6/site-packages/django/db/models/fields/", line 650, in clean
    value = self.to_python(value)
  File "/home/anteo/.envs/prisonerSolidarity/lib/python3.6/site-packages/django/db/models/fields/", line 2295, in to_python
    return memoryview(b64decode(value.encode('ascii')))
  File "/usr/lib/python3.6/", line 87, in b64decode
    return binascii.a2b_base64(s)

Exception Type: Error at /pages/person/add/
Exception Value: Incorrect padding

It looks like at that point that you’re trying to convert from base64 to ascii - but the data isn’t properly formatted base64 data.

To provide more specific help, we’d need to see the form, view, and models involved.

Thank you for the quick response!


class Person(models.Model):

name = models.CharField(max_length=50)
slug = models.SlugField(allow_unicode=True, unique=True, null=False)
bio = models.TextField(blank=True)
created = models.DateField(auto_now_add=True)
modified = models.DateField(auto_now_add=True)
birthday = models.DateField(blank=True)
projected_release = models.DateField(blank=True)
next_parole_date = models.DateField(blank=True)
(FACING_CHARGES, “Facing Charges, Not Incarcerated”),
(JAILED, “Jailed (awaiting charges or shorter sentence”),
(IMPRISONED, “Imprisoned”),
(RELEASED, “Released”),
(DECEASED, “Deceased”)
legal_status = models.CharField(
mailing_address = models.CharField(max_length=150, blank=True)
imprisoned_by = CountryField()
mailing_suggestions = models.CharField(max_length=250, blank=True)
support_crew = models.BinaryField(default=False, editable=True)
support_email = models.EmailField(blank=True)
support_url = models.URLField(blank=True)
donation_url = models.URLField(blank=True)
wishlist_url = models.URLField(blank=True)
support_fb = models.URLField(blank=True)
support_twitter = models.URLField(blank=True)
support_mastadon = models.URLField(blank=True)
support_instagram = models.URLField(blank=True)
bitcoin = models.CharField(max_length=35, blank=True)
pic = models.ImageField(upload_to=‘page_pics/’, null=True, blank=True)
brochure = models.FileField(upload_to=‘brochures/’, null=True, blank=True)
adopter = models.ManyToManyField(User)

def save(self, *args, **kwargs):
self.slug = slugify(
super().save(*args, **kwargs)

def str(self):


class PersonAdd(edit.CreateView, LoginRequiredMixin):
model = Person
form_class = PersonAddForm
template_name = ‘pages/person_add.html’


from django import forms
from django.utils.translation import gettext_lazy as _
from PIL import Image
from .models import Agency, Case, Movement, Person, Prison

class PersonAddForm(forms.ModelForm):
class Meta:
fields = [
model = Person
labels = {
‘mailing_address’ : _(‘Last Known Address’),
widgets = {
‘birthday’ : forms.DateInput(format=’%B %d, %Y’),
‘projected_release’ : forms.DateInput(format=’%B %d, %Y’),
‘next_parole_date’ : forms.DateInput(format=’%B %d, %Y’),

Without having had a chance to actually try this, I’m going to go way out on a limb and say this might be the cause of the problem:

(Initial Conjecture with no direct knowledge to support this - “False” is a boolean type and may not be an appropriate default for that field. I’d be inclined to try it as null=True instead of default=False)

If I were investigating this, I’d probably first try to create a Person object from within the shell, without assigning a value to that field. If that works, then I’d want to figure out which field is causing the error.
Depending upon what I had set up in my development environment, I’d either:

  • Run it in the debugger to catch the exception to determine what field is causing the problem
  • Run it under runserver_plus and use the Werkzeug browser-based debugging tool to see what’s happening.

Any steps beyond that are going to be determined by what is found above.

1 Like

Yeah, I don’t recall putting “BinaryField” in there, i meant BooleanField. I changed that, deleted migrations and database, ran the migrations and started the server and it seems to be working now with null=True and blank=True. I really appreciate you pointing that out and am going to keep plugging along. This was my first experience on this forum (mostly have been looking up answers in StackOverflow) and this was quite helpful. Thanks!