Questions tagged [bytesio]

A stream implementation using an in-memory bytes buffer.

Refer to BytesIO class details in Python's docs.

258 questions
1
vote
0 answers

How to concatenate bytesio object in python?

I created a main bytesIO object that will concatenate additional bytesIO object. csv_file = BytesIO for _ in range(iterations): sliced_queryset = queryset[start_index:end_index] serialized = serializer(sliced_queryset,…
juicymango
  • 201
  • 1
  • 4
  • 14
1
vote
1 answer

Saving zip file in python to disk

I have a bytea object in a database which is a zip file, I can retrieve it and read it as a zip file, but I also want to save it to disk. I can't work out how to write zf_model to disk. I've also tried zf.write(io.BytesIO(model.model_file)), i.e.…
yahop19531
  • 193
  • 1
  • 11
1
vote
0 answers

loading numpy array from bytesIO

I'm trying to load an io bytes stream into a numpy array. np.frombuffer() returns an array with too many elements and np.load() throws the error "UnicodeDecodeError: 'utf-8' codec can't decode byte 0x93 in position 0: invalid start byte" Can anyone…
nallekavn
  • 11
  • 2
1
vote
2 answers

problem with line terminator \n on dataframe and .csv

Im getting (with an python API) a .csv file from an email attachment that i received in gmail, transforming it into a dataframe to make some dataprep, and saving as .csv on my pc. It is working great, the problem is that i get '\n' on some…
1
vote
1 answer

Error while sending an image in response [FLASK]

I have an image file on a server that is protected by Windows Authentication which I have to access. I used the requests_ntlm module of python to access the file with Windows Auth, which I was able to. However, on sending this data back as an image,…
Naman Sharma
  • 179
  • 1
  • 1
  • 12
1
vote
1 answer

PIL - saving file in memory?

I just want to open the image files in a folder, and convert them to jpeg if they are not already jpeg. Only thing is I need to save the file in memory, not to file. The reason is, in fact I'm reading the images from tfrecod file (tensorflow data…
Ahmet Cetin
  • 3,683
  • 3
  • 25
  • 34
1
vote
1 answer

XlsxWriter: Why does in_memory give a corrupt byte sequence?

I am generating an excel file and returning it for download in a flask app. If I use 'in_memory': True then the file is corrupt and excel can't open it. The same code if written directly to disk works. For the in-memory code I'm following this…
Eric Grunzke
  • 1,487
  • 15
  • 21
1
vote
1 answer

Trying to display images with PIL and BytesIO but returns nothing

I'm trying to display the logos from a dataset. The dataset looks like this: Player Club Logo tom https://abc.png jerry https://def.png peter https://frf.png woody https://awt.png However, it didnt return me…
Jonathan
  • 424
  • 4
  • 14
1
vote
1 answer

Load numpy arrays from compressed bytes

I'm trying to save (using savez_compressed) a bunch of numpy arrays into a BytesIO object and then load them back to a variable. So far, I can save the array's using following code # Arrays a = numpy.random.uniform(size=(10,10)) # dtype is float64 b…
Rikard Olsson
  • 841
  • 1
  • 7
  • 28
1
vote
2 answers

Convert PIL Image to Bytes, getting Error

The solutions I have found said to: from PIL import Image import io img = "1.jpg" image = Image.open(img) # ... other processing... buf = io.BytesIO() image.save(buf, format="JPEG") buf.get_value() But I get the error: Traceback (most recent…
Lisa
  • 55
  • 1
  • 6
1
vote
0 answers

Open Image from requests.response.content

What I am trying to do is quite simple when dealing with a local file, but the problem comes when I try to do it with a remote URL. Basically, I am trying to create a PIL image object from a file extracted from a URL. Of course, I could always fetch…
1
vote
2 answers

Using BytesIO and Flask send_file

I need to process an xml file and send it back, storing all in-memory. I tried to use BytesIO as a file-like object. Initially, I tried this: with BytesIO() as file: data.write(file, encoding='windows-1251') return…
Alex
  • 11
  • 1
  • 5
1
vote
1 answer

A image converted with canvas fails to be read by python PIL _io.BytesIO

Python PIL rejects to read an image you have resized with Javascript canvas I resize an image on the client-side with Javascript: var reader = new FileReader(); reader.onload = function (e) { el('image-picked').src = e.target.result; …
brunosan
  • 295
  • 2
  • 6
  • 17
1
vote
1 answer

Why isn't this string saving in the global variable?

I'm writing an app using Python and Kivy. I have a function that draws an image and exports it as a png. I'm trying to use that image and save it in a sql db as a BLOB. The route I'm trying to take is to convert the png in to a stream using BytesIO…
Cl0ud-l3ss
  • 175
  • 2
  • 10
1
vote
1 answer

Read with MXRecordIO from bytes object

Is there a way that I can use mx.recordio.MXRecordIO to read from a bytes object rather than a file object? For example I'm currently doing: import mxnet as mx results_file = 'results.rec' with open(results_file, 'wb') as f: …
Austin
  • 6,921
  • 12
  • 73
  • 138