# Buggy code
def _get_mime_headers(self):
    headers = []
    headers.append(("Project-Id-Version", "%s %s" % (self.project, self.version)))
    headers.append(("Report-Msgid-Bugs-To", self.msgid_bugs_address))
    headers.append(
        (
            "POT-Creation-Date",
            format_datetime(self.creation_date, "yyyy-MM-dd HH:mmZ", locale="en"),
        )
    )
    if isinstance(self.revision_date, (datetime, time_) + number_types):
        headers.append(
            (
                "PO-Revision-Date",
                format_datetime(self.revision_date, "yyyy-MM-dd HH:mmZ", locale="en"),
            )
        )
    else:
        headers.append(("PO-Revision-Date", self.revision_date))
    headers.append(("Last-Translator", self.last_translator))
    if self.locale is not None:
        headers.append(("Language", str(self.locale)))
    if (self.locale is not None) and ("LANGUAGE" in self.language_team):
        headers.append(
            ("Language-Team", self.language_team.replace("LANGUAGE", str(self.locale)))
        )
    else:
        headers.append(("Language-Team", self.language_team))
    if self.locale is not None:
        headers.append(("Plural-Forms", self.plural_forms))
    headers.append(("MIME-Version", "1.0"))
    headers.append(("Content-Type", "text/plain; charset=%s" % self.charset))
    headers.append(("Content-Transfer-Encoding", "8bit"))
    headers.append(("Generated-By", "Babel %s\n" % VERSION))
    return headers


# Traceback (babel.core.UnknownLocaleError)
Traceback (most recent call last):
File "/usr/local/bin/pybabel", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.5/dist-packages/babel/messages/frontend.py", line 908, in main
return CommandLineInterface().run(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/babel/messages/frontend.py", line 832, in run
return cmdinst.run()
File "/usr/local/lib/python3.5/dist-packages/babel/messages/frontend.py", line 182, in run
self._run_domain(domain)
File "/usr/local/lib/python3.5/dist-packages/babel/messages/frontend.py", line 221, in _run_domain
catalog = read_po(infile, locale)
File "/usr/local/lib/python3.5/dist-packages/babel/messages/pofile.py", line 331, in read_po
parser.parse(fileobj)
File "/usr/local/lib/python3.5/dist-packages/babel/messages/pofile.py", line 265, in parse
self._process_comment(line)
File "/usr/local/lib/python3.5/dist-packages/babel/messages/pofile.py", line 224, in _process_comment
self._finish_current_message()
File "/usr/local/lib/python3.5/dist-packages/babel/messages/pofile.py", line 164, in _finish_current_message
self._add_message()
File "/usr/local/lib/python3.5/dist-packages/babel/messages/pofile.py", line 158, in _add_message
self.catalog[msgid] = message
File "/usr/local/lib/python3.5/dist-packages/babel/messages/catalog.py", line 596, in __setitem__
self.mime_headers = _parse_header(message.string).items()
File "/usr/local/lib/python3.5/dist-packages/babel/messages/catalog.py", line 399, in _set_mime_headers
self.locale = Locale.parse(value)
File "/usr/local/lib/python3.5/dist-packages/babel/core.py", line 331, in parse
raise UnknownLocaleError(input_id)
babel.core.UnknownLocaleError: unknown locale 'sr_SP'

# Fixed code
def _get_mime_headers(self):
    headers = []
    headers.append(("Project-Id-Version", "%s %s" % (self.project, self.version)))
    headers.append(("Report-Msgid-Bugs-To", self.msgid_bugs_address))
    headers.append(
        (
            "POT-Creation-Date",
            format_datetime(self.creation_date, "yyyy-MM-dd HH:mmZ", locale="en"),
        )
    )
    if isinstance(self.revision_date, (datetime, time_) + number_types):
        headers.append(
            (
                "PO-Revision-Date",
                format_datetime(self.revision_date, "yyyy-MM-dd HH:mmZ", locale="en"),
            )
        )
    else:
        headers.append(("PO-Revision-Date", self.revision_date))
    headers.append(("Last-Translator", self.last_translator))
    if self.locale_identifier:
        headers.append(("Language", str(self.locale_identifier)))
    if self.locale_identifier and ("LANGUAGE" in self.language_team):
        headers.append(
            (
                "Language-Team",
                self.language_team.replace("LANGUAGE", str(self.locale_identifier)),
            )
        )
    else:
        headers.append(("Language-Team", self.language_team))
    if self.locale is not None:
        headers.append(("Plural-Forms", self.plural_forms))
    headers.append(("MIME-Version", "1.0"))
    headers.append(("Content-Type", "text/plain; charset=%s" % self.charset))
    headers.append(("Content-Transfer-Encoding", "8bit"))
    headers.append(("Generated-By", "Babel %s\n" % VERSION))
    return headers