-
-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Illegal seek on macOS #28
Comments
Using ChatGTP 4.0 / CodeInterpreter ChatGPT: The error message indicates that there is an issue with the file object being used. The The One possible solution to this problem is to make sure that the file object supports seeking. This could mean opening the file in a mode that supports seeking, like However, this is more likely a bug in the Also, as Python 3.11 is relatively new at the time of your issue, it could be that the library has not yet been fully updated to support this version of Python. You might want to try using an older version of Python to see if the issue persists. Lastly, it's worth noting that the Python standard library has a metaist: I'm the author of pdfmerge and I'm trying to fix this error. The comment about a network stream, seems interesting because this seems to happen when merging PDFs that are mounted using ChatGPT: Detecting whether a file object is a network stream can be challenging because Python's file objects don't have a built-in way to check this. In general, the best way to check whether a file is a network stream might be to attempt a def is_seekable(fileobj):
try:
fileobj.seek(fileobj.tell())
return True
except OSError:
return False In this function, we're checking whether we can seek to the current position in the file (which should always be a no-op if seeking is supported). If this raises an For dealing with network streams, writing to a temporary file is a common workaround. In fact, Python has a built-in library for creating temporary files and directories that you could use: import tempfile
def write_to_tempfile(fileobj):
with tempfile.NamedTemporaryFile(delete=False) as temp:
shutil.copyfileobj(fileobj, temp)
return temp.name In this function, we're creating a temporary file, copying the contents of Once you have the temporary file, you can perform whatever operations you need on it (like seeking), and then move it to its final location when you're done. Just be sure to delete the temporary file when you're done with it to avoid wasting disk space. Python's Of course, this is just one possible solution. Depending on your specific needs and the characteristics of your network stream, there might be other, more efficient ways to handle this situation. |
OS: macOS 13.4.1 (22F82)
Python: 3.11
When running
pdfmerge
on python 3.11, the following error occurs:Looks like something is wrong with the way the steam is constructed and passed to
pypdf
.The text was updated successfully, but these errors were encountered: