Функция str до последнего момента все хранит в наборе байтов (как надо), но при return ‘\r\n’.join(flattened) все сбивается и выдает крякозяблы… такое чувство, что питон зачем то произвел encode.. Почему и как это отменить?
Content-Disposition: file; name="file"; filename="dd.docx" Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
XKnDUContent_Types].xml (Tn0W?D8H` A*)Yl 1iJ/z,'nVK~)am j0HuT9bx<9X Q 8AO1~qk I~8WZ"V0}>uQwHoP!N_UZB_%D[S+?#[.z9>$N{9+P9Y vuGDoR _rels/.rels (JA Х{дальше в том же духе}
def __str__(self):
"""Return a string representing the form data, including attached files."""
# Build a list of lists, each containing "lines" of the
# request. Each part is separated by a boundary string.
# Once the list is built, return a string where each
# line is separated by '\r\n'.
parts = []
part_boundary = '--' + self.boundary
# Add the form fields
parts.extend(
[ part_boundary,
'Content-Disposition: form-data; name="%s"' % name,
'',
value,
]
for name, value in self.form_fields
)
# Add the files to upload
parts.extend(
[ part_boundary,
'Content-Disposition: file; name="%s"; filename="%s"' % \
(field_name, filename),
'Content-Type: %s' % content_type,
'',
body,
]
for field_name, filename, content_type, body in self.files
)
# Flatten the list and add closing boundary marker,
# then return CR+LF separated data
flattened = list(itertools.chain(*parts))
flattened.append('--' + self.boundary + '--')
flattened.append('')
return '\r\n'.join(flattened)