Questions tagged [bytesio]

A stream implementation using an in-memory bytes buffer.

Refer to BytesIO class details in Python's docs.

258 questions
3
votes
1 answer

Flask response to excel file giving me corrupt excel response

I have created endpoint to fetch data from database and download data in excel file using xmlswriter library. But rather than downloading the excel file it download text file with name 'unknown.txt' that includes data…
3
votes
1 answer

Difference between FileIO object and object returned by open(filename, mode)

Python has several io base classes including IOBase RawIOBase BufferedIOBase TextIOBase as well as several derived io classes: FileIO BytesIO Now, when i create a BytesIO object, the mro is: [, ,…
3
votes
1 answer

Reading file from a ZIP archive on FTP server without downloading to local system

My target file on the FTP server is a ZIP file, and the .CSV is located two folders further in. How would I be able to use BytesIO to allow pandas to read the csv without downloading it? This is what I have so far: ftp =…
3
votes
2 answers

How to pre-load numpy data into a buffer like io.BytesIO to make it seekable?

Following function basically returns numpy.ndarray def getimage(id): img = self.coco.loadImgs(id) I = io.imread(img['coco_url']) return I #returns 'numpy.ndarray' The getimage function being called from main: x =…
3
votes
1 answer

How to create an BytesIO img and pass to template

AIM I am attempting to: Create a histogram, Store it temporary memory, Pass the image to the template. I am having trouble with Step 3 above. I suspect that I am making a simple and fundamental error in relation to passing the context data to the…
Darcy
  • 575
  • 2
  • 8
  • 21
3
votes
1 answer

Python3 Requests "Post" Ignoring Filename when using BytesIO?

I've written a simple script to expand my skills with python - however I've noticed something very strange when using BytesIO. Here's my working script: import requests url = "http://MY.FAKE.IP.ADDR/Uploader.php" file = open("test.jpg","rb") action…
Piero Bird
  • 119
  • 1
  • 10
3
votes
1 answer

Image download mime type validation python requests

I use the requests library in python to download a large number of image files via http. I convert the received content to raw bytes using BytesIO in python and then use Pillow() to save this raw content as a jpeg file. from PIL import Image from io…
3
votes
1 answer

Converting PIL image to VIPS image

I'm working on some large histological images using Vips image library. Together with the image I have an array with coordinates. I want to make a binary mask which masks out the part of the image within the polygon created by the coordinates. I…
Rune
  • 33
  • 2
3
votes
1 answer

Django the powerpoint generated using python-pptx library has error message

I use python-pptx v0.6.2 to generate powerpoint. I read a exist powerpoint into BytesIO, then do some modification and save it. I can download the file successfully, and I'm sure the content can be write into the file. But when I open the…
Leon Chen
  • 53
  • 1
  • 8
3
votes
2 answers

How to get the length of a type after serializization

I encounter a problem that with Java, I have a map,such as map, K and V can be arbitrary type, e.g int, Long, String, Time, etc. After the map is serialized, can I get the length of K or the V? Can I write a common method to implement this…
user3231931
  • 331
  • 1
  • 2
  • 8
2
votes
1 answer

does read method of io.BytesIO returns copy of underlying bytes data?

I am aware that io.BytesIO() returns a binary stream object which uses in-memory buffer. but also provides getbuffer() which provides a readable and writable view (memoryview obj) over the contents of the buffer without copying them. obj =…
Scarface
  • 359
  • 2
  • 13
2
votes
0 answers

How to use bytesio in functions that only support path?

The function I use accepts only one path parameter. But the file data is in memory. It's too slow to open it after save. Is there any way to wrap bytesio into a path then i can pass it to the function?
simpia
  • 65
  • 7
2
votes
1 answer

Passing base64 .docx to docx.Document results in BadZipFile exception

I'm writing an Azure function in Python 3.9 that needs to accept a base64 string created from a known .docx file which will serve as a template. My code will decode the base64, pass it to a BytesIO instance, and pass that to docx.Document().…
2
votes
1 answer

Load Model from BytesIO using Joblib

I have converted a model to a BytesIO object using joblib in the following way: from io import BytesIO import joblib bytes_container = BytesIO() joblib.dump(model, bytes_container) bytes_container.seek(0) # update to enable reading bytes_model =…
2
votes
1 answer

pillow: image to bytes to image

My function accepts bytes to internaly opens them as a PIL.Image object. The function works as expected when bytes are passed to it. But I would like to write a couple of tests to it. So I need to generate images, turn them into bytes and pass them…
Denny Crane
  • 637
  • 6
  • 19