You know filename, it is the file you were reading and calculating the CRC for. For errno and strerror I would pick from the list of defined errors in libc. This is where the reasons of most IOErrors originate from, so lets keep this implementation detail for consistency. Which values to pick is somewhat arbitrary (and not completely OS independent), I'd try convey the general meaning of my problem without being too specific.

You could take one of these (the comment would be strerror):

EIO          5  /* I/O error */
EINVAL      22  /* Invalid argument */

Being too specific with such a "fake" libc error could send people debugging a problem on the wrong track.

BTW I consulted this list for existing errno's

Answer from knitti on Stack Overflow
🌐
AskPython
askpython.com › python › examples › handling-ioerrors
Handling Built-in Exception IOError in Python (With Examples) - AskPython
May 8, 2023 - In this Python tutorial, we will learn when the IOError occurs, Identify an IOError and how to handle it. IOError exception is raised when an input or output operation is taking place, there can be many reasons for this.
Discussions

IOError exception (in Python 2.7.2?
Error seems very clear ... the file you are trying to open is not a gzipped file. Try adding a print statement to see what file it's working on. for files in f: print files # etc I'll guess it's because your glob pattern was meant to be ./*.gz More on reddit.com
🌐 r/learnpython
3
1
November 12, 2020
GreenFileDescriptorIO.seek should raise IOError, not OSError
gevent version: 1.3.7 Python version: "cPython 2.7.15" Operating System: "Arch on amd64" Description: GreenFileDescriptorIO should raise an IOError exception instead of an OSErr... More on github.com
🌐 github.com
1
November 29, 2018
Error "raise IOError(text)" when transfer file
And I found stackoverflow has gave the error: Python paramiko SFTP IOError More on github.com
🌐 github.com
4
August 23, 2018
Raising builtin exception with default message in python - Stack Overflow
Why don't you want to raise the ... with raise OSError(...)? It's a perfectly valid way of telling your caller that there is a problem. ... Exactly what I was trying to do ~ I was just looking for a way to access the built-in error messages. ... Save this answer. ... Show activity on this post. Copyimport os try: open('foo') except IOError as err: print(err) ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Georgevreilly
georgevreilly.com › blog › 2016 › 03 › 24 › RaisingIOErrorForFileNotFound.html
Raising IOError for 'file not found' - George V. Reilly
March 24, 2016 - from errno import ENOENT if not os.path.isfile(source_file): raise IOError(ENOENT, 'Not a file', source_file) with open(source_file) as fp: return fp.read() IOError can be in­stan­ti­at­ed with 1, 2, or 3 arguments: ... These arguments are available on the errno, strerror, and filename attributes of the exception object, re­spec­tive­ly, in both Python 2 and 3.
🌐
Program Creek
programcreek.com › python
Python raise ioerror
def raise_ioerror(error): try: message = Image.core.getcodecstatus(error) except AttributeError: message = ERRORS.get(error) if not message: message = "decoder error %d" % error raise IOError(message + " when reading image file") # # -------------------------------------------------------------------- # Helpers
🌐
Initial Commit
initialcommit.com › blog › python-ioerror
IOError in Python | How to Solve with Examples - Initial Commit
The io error has more to it than the exception it throws, and it's important to understand that going forward. An io error is raised during the failure of an input/output system task. In Python...
🌐
O'Reilly
oreilly.com › library › view › learn-python-in › 9781787288386 › f256a15d-c8be-4c61-9f38-4b006d00d820.xhtml
Raising exceptions - Learn Python in 7 Days [Book]
Content preview from Learn Python in 7 Days · The raise statement allows the programmer to trigger specific exceptions explicitly. Consider the following example: >>> raise IOErrorTraceback (most recent call last): File "<pyshell#0>", line ...
🌐
EDUCBA
educba.com › home › software development › software development tutorials › python tutorial › python ioerror
Python IOError | How IOError work in Python with Programming Examples
April 13, 2023 - IOError in Python is a result of incorrect file name or location. This error is raised in multiple conditions and all these conditions can be handled using try except code block. We saw the working of the error with examples and saw how to avoid it.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Python
docs.python.org › 3 › builtins › exceptions.html
Built-in Exceptions — Python 3.14.7 documentation
Changed in version 3.4: The filename ... constructor argument and attribute was added. ... Raised when the result of an arithmetic operation is too large to be represented....
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › How-to-catch-IOError-Exception-in-Python
How to catch IOError Exception in Python?
This will raise an IOError if the file cannot be written to - Write error: [Errno 30] Read-only file system: '/readonly.txt' In Python 3, IOError was merged into the OSError, so you can rely on OSError alone to catch both kinds of errors, though for backward compatibility, you can still use except OSError or except (IOError, OSError).
🌐
Real Python
realpython.com › ref › builtin-exceptions › ioerror
IOError | Python’s Built-in Exceptions – Real Python
In Python, IOError is a built-in ... files. This exception was commonly raised when an I/O operation failed for an I/O-related reason, such as file not found or disk full....
🌐
Reddit
reddit.com › r/learnpython › ioerror exception (in python 2.7.2?
r/learnpython on Reddit: IOError exception (in Python 2.7.2?
November 12, 2020 -

Hello, I am trying to read from the .gz file and it is giving me the following error. Below are the code and traceback.

f = glob.glob (*/.gz)
if f:
    for files in f:
        with zgip.open(files, 'r') as r:
            for line in r:
                for i in range (3):
                    print line

Traceback:

Traceback (most recent call last):
  File "tst.py", line 14, in <module>
    for line in r:
  File "python2.7/gzip.py", line 446, in readline
    c = self.read(readsize)
  File "python2.7/gzip.py", line 252, in read
    self._read(readsize)
  File "python2.7/gzip.py", line 287, in _read
    self._read_gzip_header()
  File "python2.7/gzip.py", line 181, in _read_gzip_header
    raise IOError, 'Not a gzipped file'
IOError: Not a gzipped file

Please help me in solving this.

🌐
Mouse Vs Python
blog.pythonlibrary.org › home › python 101 – exception handling
Python 101 - Exception Handling - Mouse Vs Python
June 17, 2020 - >>> try: ... raise IOError ... print('This is the try block') ... except IOError: ... print('An IOError has occurred') ... else: ... print('This is the else block') ... An IOError has occurred · Since an exception was raised, only the try and the except blocks ran. Note that the try block stopped running at the raise statement. It never reached the print() function at all. Once an exception is raised, all the following code is skipped over and you go straight to the exception handling code. Now you know the basics of using Python’s built-in exception handling.
🌐
Readthedocs
docspy3zh.readthedocs.io › en › latest › library › exceptions.html
5. Built-in Exceptions — Python 3 文档(简体中文) 3.2.2 documentation
Some built-in exceptions (like IOError) expect a certain number of arguments and assign a special meaning to the elements of this tuple, while others are usually called only with a single string giving an error message. ... This method sets tb as the new traceback for the exception and returns the exception object. It is usually used in exception handling code like this: try: ... except SomeException: tb = sys.exc_info()[2] raise OtherException(...).with_traceback(tb)
🌐
GitHub
github.com › gevent › gevent › issues › 1323
GreenFileDescriptorIO.seek should raise IOError, not OSError · Issue #1323 · gevent/gevent
November 29, 2018 - With the current implementation (using os.lseek internally) raising an OSError will break expectations of the file-like interface. For example, when using gevent in conjunction with boto, boto will catch IOError while trying to seek a file and handle it accordingly, but will fail to notice gevent raising an OSError (as it's not what the __builtins__ or io based file-like objects do).
Author: gevent
🌐
GitHub
github.com › fabric › fabric › issues › 1860
Error "raise IOError(text)" when transfer file · Issue #1860 · fabric/fabric
August 23, 2018 - my code is from fabric import Connection result = Connection('xx.xx.xx.xx').put('/tmp/wan.txt', remote='/tmp/') print("Uploaded {0.local} to {0.remote}".format(result)) I got Error: /.local/share/virtualenvs/playbook-zVtSjadl/lib/python3...
Author: fabric
🌐
Python Course
python-course.eu › python-tutorial › errors-and-exception-handling.php
32. Errors and Exception Handling | Python Tutorial
import sys try: f = open('integers.txt') s = f.readline() i = int(s.strip()) except IOError as e: errno, strerror = e.args print("I/O error({0}): {1}".format(errno,strerror)) # e can be printed directly without using .args: # print(e) except ValueError: print("No valid integer in line.") except: print("Unexpected error:", sys.exc_info()[0]) raise ·
🌐
Python
peps.python.org › pep-3151
PEP 3151 – Reworking the OS and IO exception hierarchy | peps.python.org
July 21, 2010 - Given the following kind of snippet, all exceptions caught before this PEP will also be caught after this PEP, but the reverse may be false (because the coalescing of OSError, IOError and others means the except clause throws a slightly broader net): try: ... os.remove(filename) ... except OSError: pass · useful compatibility doesn’t alter the behaviour of careful exception-catching code. Given the following kind of snippet, the same errors should be silenced or re-raised, regardless of whether this PEP has been implemented or not:
🌐
Python Tips
book.pythontips.com › en › latest › exceptions.html
17. Exceptions — Python Tips 0.1 documentation
try: file = open('test.txt', 'rb') except (IOError, EOFError) as e: print("An error occurred. {}".format(e.args[-1])) Another method is to handle individual exceptions in separate except blocks. We can have as many except blocks as we want. Here is an example: try: file = open('test.txt', 'rb') except EOFError as e: print("An EOF error occurred.") raise e except IOError as e: print("An error occurred.") raise e