Найти - Пользователи
Полная версия: Преобразование батовой записи в крякозяблы
Начало » Python для новичков » Преобразование батовой записи в крякозяблы
1
exact2007
Функция 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)        
    
adray
Нельзя так просто взять и прочитать docx. Это архив
exact2007
Я и не собирался читать для получения информации. Мне нужно передать данный файл на другой сервер
adray
encode вызывается при выводе в stdout. Чтобы вывести байтовое представление строки можно использовать repr
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB