Skip to content

io.UnsupportedOperation: fileno #2

Description

@eeriemyxi

I am getting this error on a fairly simple script.

import sixel
import io

def main():
    with open("box.png", "rb") as img:
        f = io.StringIO()
        # f = io.BytesIO()
        writer = sixel.SixelWriter()
        writer.draw(img, output=f)

if __name__ == "__main__":
    main()
Traceback (most recent call last):
  File "/home/myxi/Documents/coding/python/dumps/test.py", line 12, in <module>
    main()
  File "/home/myxi/Documents/coding/python/dumps/test.py", line 9, in main
    writer.draw(img, output=f)
  File "/home/myxi/.asdf/installs/python/3.11.8/lib/python3.11/site-packages/sixel/sixel.py", line 69, in draw
    self.save_position(output)
  File "/home/myxi/.asdf/installs/python/3.11.8/lib/python3.11/site-packages/sixel/sixel.py", line 24, in save_position
    if os.isatty(output.fileno()):
                 ^^^^^^^^^^^^^^^
io.UnsupportedOperation: fileno

I have tried both StringIO and BytesIO, but the error persists. The script worked fine on my machine when I wrote to sys.stdout for some reason. I did some googling and found out that this can be caused if you run the script in a limited environment of Python as offered by certain IDEs, but I am not running it in such an environment. I run it directly. This is how I run the command:

python test.py

The funny part is that this worked just fine:

import sixel
import io

def main():
    with open("box.png", "rb") as img:
        f = io.StringIO()
        conv = sixel.converter.SixelConverter(img)
        conv.write(f)

if __name__ == "__main__":
    main()

No errors. But I need the writer because I need to specify the position of the image.

I have tried the first script on Python 3.11.8 and Python 3.12.2. I get this error on both.

myxi :: coding/python/dumps » pip freeze
pillow==10.2.0
sixel==0.2.0
myxi :: coding/python/dumps » uname -a
Linux myxi 6.5.0-25-generic #25~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Feb 20 16:09:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Python versions were compiled with gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions