Questions tagged [stringio]

Use for questions concerning the Python 2 module StringIO or the class StringIO it contains. In Python 3, this refers to the class StringIO of the io module.

Python class StringIO allows to read and write a string buffer (also known as memory files).

355 questions
2
votes
0 answers

Boto3 s3 put operation getting "HTTPClientError"

I started getting this error when trying to put a test csv to s3: HTTPClientError: An HTTP Client raised and unhandled exception: Timeout value connect was Timeout(connect=60, read=60, total=None), but it must be an int, float or None. It was…
L Xandor
  • 1,659
  • 4
  • 24
  • 48
2
votes
0 answers

pstats print_stats() throws error TypeError: descriptor 'write' requires a '_io.StringIO' object but received a 'str'

I want to write profiler decorator as in the example of official documentation of cProfiler. But I get TypeError. I have debugged and in pstats module this line throws the exception: print(indent, self.total_calls, "function calls",…
user3338094
  • 83
  • 1
  • 8
2
votes
0 answers

ImportError: cannot import name 'StringIO'

I am trying to get data from yahoo of stocks of a company through the code. But i am getting an ImportError at pandas_datareader.data where is says ImportError: cannot import name 'StringIO' Please help I am new to this...and already spent 4 hrs…
jai arora
  • 21
  • 2
2
votes
2 answers

How to export dataframe to csv in bucket on google cloud

I'm trying to export a pandas dataframe to a csv file in a bucket on my google cloud storage, but the following code obviously isn't working for me: my_df.to_csv(StringIO(file_io.FileIO('gs://mybucket/data/file.csv', mode='w+'))) How should this be…
2
votes
2 answers

Porting json.dump into StringIO code to python 3

I'm porting a Python 2 application to Python 3. Currently running Python2.7 but, updating code to pass pylint --py3k tests, I have run into a problem with this: def json_resource_file(baseurl, jsondata, resource_info): """ Return a file…
Graham Klyne
  • 816
  • 10
  • 16
2
votes
2 answers

String IO to element.etree

I want to parse StringIO in form of xml with etree, hovever I have following error. Example: import xml.etree.ElementTree from io import StringIO def main(): in_mem_file = StringIO() in_mem_file.write('
user2678074
  • 768
  • 3
  • 9
  • 22
2
votes
2 answers

use stringIO object as ssl key/cert file

I want to pull my ssl certificate and key from environment variables and not store them on the filesystem. But I am running into a road block with twisted ssl from io import StringIO from twisted.internet import reactor, task, threads, ssl key =…
user1601716
  • 1,893
  • 4
  • 24
  • 53
2
votes
2 answers

no module named StringIO

I have python 3.6. I want to execute python file named 'operation.py' from another python file named 'run.py'. In operation.py I do from cStringIO import StringIO. PyCharm shows me a warning that there is no module named StringIO. I know that since…
user9399101
  • 71
  • 1
  • 1
  • 3
2
votes
2 answers

Encoding in a in-memory stream or how does TextIOBase work?

I am currently reading the documentation for the io module: https://docs.python.org/3.5/library/io.html?highlight=stringio#io.TextIOBase Maybe it is because I don't know Python well enough, but in most cases I just don't understand their…
Daniel
  • 3,092
  • 3
  • 32
  • 49
2
votes
1 answer

StringIO initial_value must be str, not Bytes

Ok so i have this code: from PIL import Image import os, sys import requests from io import StringIO url = "https://cdn.discordapp.com/avatars/247096918923149313/34a66572b9339acdaa1dedbcb63bc90a.png?size=256" response = requests.get(url) pp =…
bob roberts
  • 31
  • 1
  • 1
  • 2
2
votes
1 answer

Textract cannot read a JpegImageFile (StringIO objects)

I suppose in-memory file-like objects are expected to behave like files. I am not able to get Textract to "read" a although the program runs fine if I save the JPEG file to disk and read in the normal…
Pradeep
  • 350
  • 3
  • 16
2
votes
1 answer

How to provide private key as string to paramiko for an ssh connection?

I am trying to use ssh to connect to server using Python paramiko package. When I tried to ssh into server using "pem" key then it worked but when I tried it by taking private key content in a string it shows an error. With the following code: …
Kriti Singh
  • 49
  • 1
  • 5
2
votes
1 answer

How can Pillow open uploaded image file from StringIO directly?

User upload a image file by the Form, I don't want to save original uploaded image file to disk, and resize image by Pillow opening image from disk. I want to resize this image file in memory first, then save the resized image file to disk. so I…
rogwan
  • 177
  • 1
  • 4
  • 12
2
votes
1 answer

Context manager for logging equivalent to contextmanager=>yield stdout

A library I'm using takes a function like this: @contextlib.contextmanager def stdout_cm(): yield sys.stdout Now rather than foo(stdout_cm), how do I send through a logging instance that tees to multiple handlers? (stdout and…
A T
  • 13,008
  • 21
  • 97
  • 158
2
votes
1 answer

Python logging to stdout and StringIO

Attempt [see it running here]: from sys import stdout, stderr from cStringIO import StringIO from logging import getLogger, basicConfig, StreamHandler basicConfig(format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', …
A T
  • 13,008
  • 21
  • 97
  • 158