Questions tagged [bytesio]

A stream implementation using an in-memory bytes buffer.

Refer to BytesIO class details in Python's docs.

258 questions
2
votes
1 answer

google cloud storage upload from bytes fails

I am trying to create a file on the fly in python and then upload this to google cloud storage but I am failing to be able to upload from a string or bytes object. The basic setup of the script is from google.cloud import storage storage_client =…
Charlie Morton
  • 737
  • 1
  • 7
  • 17
2
votes
1 answer

Discord sending blank text file with BytesIO

I'm trying to send a text file with discord.py, but when I send the file, it seems to be empty. An example snippet: bytes = BytesIO() test = b'sadfasdfsa' bytes.write(test) print(bytes) await ctx.send(file=File(bytes, 'test.txt')) This results in…
cclloyd
  • 8,171
  • 16
  • 57
  • 104
2
votes
1 answer

stream body full when sent from FastAPI, empty when received by requests

I have an api in which the server sends a stream of data to the client. On the server-side, the stream object is populated. I can verify this by writing to a file on the server before sending. But when the client receives the stream and tries to…
SkippyElvis
  • 100
  • 6
2
votes
0 answers

How to troubleshoot corrupted BytesIO return in django?

I've got a strange issue going on in django, and am not sure how to even start troubleshooting it. I am using xlsxwriter to generate an Excel report from some data. I then want to pass the generated file back to the user. My view code looks…
MarkD
  • 4,864
  • 5
  • 36
  • 67
2
votes
1 answer

How to send multiple plots generated by matplotlib to a pptx without any overlapping?

I am working on a project where I am generating hundreds of plots using the matplotlib module in Python. I want to put these plots in a pptx using the python-pptx module, let's say four plots on a slide without storing these plots on the local…
Sud_Hashira
  • 29
  • 1
  • 3
2
votes
1 answer

BytesIO.truncate method does not extend buffer contents

The documentation of IOBase.truncate method says that: truncate(size=None) Resize the stream to the given size in bytes (or the current position if size is not specified). The current stream position isn’t changed. This resizing can extend or…
2
votes
1 answer

BytesIO replaces transparency in PNG files with black background

I want to keep transparent background at my 'image' variable. If I write into a file, image looks fine. I mean image has a transparent background. with urllib.request.urlopen(request) as response: imgdata = response.read() with…
eknbrk
  • 187
  • 1
  • 1
  • 16
2
votes
1 answer

Python - load an in-memory ZipFile object as bytes

I have a script which creates a closed in-memory ZipFile object that I need to post as a bytestring (using requests); how do I do that? I have tried opening the file, which fails with "TypeError: expected str, bytes or os.PathLike object, not…
Tim Achee
  • 37
  • 1
  • 3
2
votes
1 answer

pandas does pd.read_table support io.BytesIO and StringIO?

I have a io.BytesIO object, iostream, which is a be2 file read from disk, and I am going to append column headers to the table/iostream, f = io.BytesIO() f.write(b'A,B,C,D\n') f.write(iostream.getvalue()) pd.read_table(f, sep=',', index_col=False,…
daiyue
  • 7,196
  • 25
  • 82
  • 149
2
votes
1 answer

"a bytes-like object is required" but I am using bytes

With Python3 I have re-opened stdout in binary mode. After that when I print("Hello") it tells me that I need to use a bytes-like object. Fair enough, it's in binary mode now. However when I do this: print(b"Some bytes") I still get this…
Timmmm
  • 88,195
  • 71
  • 364
  • 509
2
votes
1 answer

In an HTML table, how to add text beside plot in jupyter notebook using python?

Any ideas on how to create a 1 X 2 HTML table where cell {0} is a matplotlib plot and cell {1} is a text description for Python 3.X? import matplotlib.pyplot as plt from io import BytesIO %matplotlib inline def add_split_screen(fig, text,…
Student
  • 1,197
  • 4
  • 22
  • 39
2
votes
3 answers

How to use BytesIO with matplotlib and pyqt5?

I made a graph in matplotlib, and wanted to make it in to an image and use it in my pyqt5 application. Someone suggested I use BytesIO for this. This is my code so far: Drawing my graph: ... plt.axis('equal') buff = io.BytesIO() plt.savefig(buff,…
2
votes
1 answer

Python3.5 error using BytesIO or StringIO with base64.standard_b64encode

I am trying to take the contents of a BytesIO or StringIO object and use base64.standard_b64encode() to encode it. I have tried both. This works fine in python 2.7, however in python 3.5 I get the following error. TypeError: Can't convert 'bytes'…
Antikythera
  • 91
  • 1
  • 8
2
votes
1 answer

how to attach a BytesIO object to a Webob.Response Object

I'm returning a Webob.Response object from my server to http request. The server puts together a BytesIO object. How can I correctly attach the BytesIO object to the Webob.Response object? I tried: app_iter = FileIter(BytesIO_Object) return…
Abdul Ahmad
  • 9,673
  • 16
  • 64
  • 127
2
votes
3 answers

Using pygame to play a MIDI file from stream

What I want to do is the following: Create a MIDI file, but only in memory, and feed it into pygame.mixer.music.load(). Here is what I've been trying (I'm using MidiFile from here): import pygame.mixer import MidiFile3 import…
ravenfrost
  • 143
  • 1
  • 1
  • 8