PydPiper / pylightxl

A light weight, zero dependency, minimal functionality excel read/writer python library
https://pylightxl.readthedocs.io
MIT License
300 stars 47 forks source link

Writing output seems to not handle Windows file paths correctly #17

Closed grantcurell closed 4 years ago

grantcurell commented 4 years ago

Steps to reproduce

path = os.path.join(os.getcwd(), "app", "test.xlsx")
xl.writexl(db, path)

To double check that path is valid I wrote:

path = os.path.join(os.getcwd(), "app", "test.xlsx")
print("Is it File? " + str(os.path.isfile(path)))

Which outputs Is it File? True.

Error

Traceback (most recent call last):
  File "C:\Users\grant\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\grant\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\grant\AppData\Roaming\Python\Python38\site-packages\flask_cors\extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "C:\Users\grant\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\grant\AppData\Roaming\Python\Python38\site-packages\flask\_compat.py", line 39, in reraise
    raise value
  File "C:\Users\grant\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\grant\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Users\path\views.py", line 362, in hardware_inventory
    xl.writexl(db, path)  # TODO - this needs to be sent back as a file
  File "C:\Users\grant\AppData\Roaming\Python\Python38\site-packages\pylightxl\writexl.py", line 50, in writexl
    alt_writer(db, path)
  File "C:\Users\grant\AppData\Roaming\Python\Python38\site-packages\pylightxl\writexl.py", line 69, in alt_writer
    f.extractall(temp_folder)
  File "C:\Program Files\Python38\lib\zipfile.py", line 1647, in extractall
    self._extract_member(zipinfo, path, pwd)
  File "C:\Program Files\Python38\lib\zipfile.py", line 1693, in _extract_member
    os.makedirs(upperdirs)
  File "C:\Program Files\Python38\lib\os.py", line 213, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "C:\Program Files\Python38\lib\os.py", line 213, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "C:\Program Files\Python38\lib\os.py", line 213, in makedirs
    makedirs(head, exist_ok=exist_ok)
  [Previous line repeated 8 more times]
  File "C:\Program Files\Python38\lib\os.py", line 223, in makedirs
    mkdir(name, mode)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '_pylightxl_C:'
INFO:werkzeug:127.0.0.1 - - [03/Aug/2020 17:06:07] "GET /api/hardware_inventory HTTP/1.1" 500 -

Update:

xl.writexl(db, os.path.relpath(path, '.'))

The above works using the relative path leading me to believe it's something about the absolute path.

xl.writexl(db, "test.xlsx")
os.replace("test.xlsx", path)

also works.

PydPiper commented 4 years ago

Hi,

Thank you for submitting this bug report. We are looking into it now

PydPiper commented 4 years ago

the latest master branch has the updates for this bug. Thank you for submitting it. Once a few more features are incorporated this will be pushed to the next pip version.