Axorax / tkforge

Drag & drop in Figma to create a Python GUI with ease

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Binary mode doesn't take an encoding argument in download_image function (core.py)

Skyunn opened this issue · comments

Hello! I am fairly new to coding.

I encountered a ValueError when running the code, specifically related to the use of the encoding argument with the open function in binary mode. The error trace is as follows:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1008.0_x64__qbz5n2kfra8p0\Lib\tkinter\__init__.py", line 1967, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\USER\Desktop\tkforge\gui.py", line 162, in generate
    code = tk_code(extract_figma_id(file), token, output)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USER\Desktop\tkforge\tk.py", line 148, in tk_code
    parsed = parse_file(file, token, True, out)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USER\Desktop\tkforge\core.py", line 142, in parse_file
    download(image_count)
  File "C:\Users\USER\Desktop\tkforge\core.py", line 106, in download
    image = download_image(file, i['id'], image_count, token, out, frame_count) if frame_count > 0 else download_image(file, i['id'], image_count, token, out)
                                                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USER\Desktop\tkforge\core.py", line 34, in download_image
    with open(file_path, 'wb', encoding='utf-8') as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: binary mode doesn't take an encoding argument

Steps to Reproduce:
Run the application with the current setup.
Trigger the function that calls download_image in core.py.

Expected Behavior:
The file should be opened in binary mode without an encoding error.

Actual Behavior:
The code throws a ValueError because the encoding argument is used with the open function in binary mode.

What I did to mitigate the error that I was having was removing encoding='utf-8' in core.py and it worked!

But the feature to support UTF-8 encoding (If that was what I removed) is now gone so I don't know how to solve the issue.

Hey there! Thanks for reporting this, I will make sure to look into it.