Nishant
Nishant

Reputation: 21914

Why do I get IOError when I use msvcrt in Python 2.x?

I am trying to generate a PDF in Windows using a HTML-PDF Web Service in Python 2.x. This link Python 2.x - Write binary output to stdout? says that I need to modify the binary file if I am writing it to stdout.

def generate_pdf():
    pdf = callservice(html)
    if pdf is not None and sys.platform == "win32":
        import os, msvcrt
        msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
    return pdf

def process():
    pdf = generate_pdf()
    # This comes as IOError Errno 12 not enough space

E:\ Drive where this program runs has 10 GB Available. Does anyone know what could be happening? C:\ Drive also has 10 GB Available. Should we check into the source code of msvcrt to see what is happening. I am trying to check that.

Upvotes: 1

Views: 685

Answers (1)

void
void

Reputation: 2799

This answer explains what is going on in principle, and the traceback would reveal an exact failed call.

In particular, an attempt to sys.stdin.read() a block of data larger than 32767 bytes will cause IOError "[Errno 12] Not enough space", when there is not enough data to read. Consider running the following example on Windows 7:

python -c "import sys; data = sys.stdin.read(32768)"

Upvotes: 1

Related Questions