chainlit icon indicating copy to clipboard operation
chainlit copied to clipboard

Permission Denied Error on Windows

Open Nneji123 opened this issue 2 years ago • 4 comments

When using the qa example code from the cookbook repo, uploading a file results in a Permission Denied error.

Also there is a file size upload limit of 2MB. Is there a way to disable this feature?

Full traceback:

$ chainlit run app.py -w 
2023-05-26 16:42:56 - Loaded .env file
2023-05-26 16:43:06 - Your app is available at http://localhost:8000
    yield from self.parser.parse(blob)
  File "c:\users\ifeanyi pc\desktop\chat-with-github-repo\env\lib\site-packages\langchain\document_loaders\base.py", line 87, in parse
    return list(self.lazy_parse(blob))
  File "c:\users\ifeanyi pc\desktop\chat-with-github-repo\env\lib\site-packages\langchain\document_loaders\parsers\pdf.py", line 16, in lazy_parse
    with blob.as_bytes_io() as pdf_file_obj:
  File "C:\Users\IFEANYI PC\.pyenv\pyenv-win\versions\3.8.10\lib\contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "c:\users\ifeanyi pc\desktop\chat-with-github-repo\env\lib\site-packages\langchain\document_loaders\blob_loaders\schema.py", line 86, in as_bytes_io   
    with open(str(self.path), "rb") as f:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\IFEANY~1\\AppData\\Local\\Temp\\tmp1_q_q2sk'

Screenshot (513)

Nneji123 avatar May 26 '23 15:05 Nneji123

For the max file size you can use the max_size_mb parameter in ask_for_file, see https://docs.chainlit.io/api-reference/ask/ask-for-file

For the permission error that looks like a langchain error at first glance. Not sure that is the issue but could you try running the chainlit run command in a terminal with admin permissions?

willydouhard avatar May 26 '23 16:05 willydouhard

Also can you try to run chainlit run without the -w option?

willydouhard avatar May 26 '23 16:05 willydouhard

I tried both options(running a terminal with admin permissions and without the -w flag) and still got the same error. Tested this on a Linux cloud environment though and it works as expected.

Nneji123 avatar May 26 '23 16:05 Nneji123

Could you try to:

  1. install chainlit from the wheel provided in this PR https://github.com/Chainlit/chainlit/pull/40
  2. run chainlit hello

I would like to see if the rework fix those issues. Note that this version is not merged yet. The infos to install are at the end of the PR's description.

willydouhard avatar Jun 08 '23 17:06 willydouhard

Should be fixed in the latest version 0.3.0. Please note that it contains breaking changes. We prepared a migration guide to make it easy for everyone.

willydouhard avatar Jun 13 '23 16:06 willydouhard

I am facing the same issue, My code is pretty much the same as the example given at https://docs.chainlit.io/api-reference/ask/ask-for-file I tried running as admin, and also without the -w:

async def start():
    await cl.Message(content="Upload a file to chat with your file").send()
    files=None
    while files is None:
        files=await cl.AskFileMessage(
            content=welcome_message,
            accept=['text/plain','application/pdf'],
            max_size_mb=20,
            timeout=180
        ).send()

    file=files[0]
    # file=file.content.decode("utf-8")
    msg=cl.Message(content=f"Processing {file.name}...")
    await msg.send()

    docsearch = await cl.make_async(get_docsearch)(file)

    chain = RetrievalQAWithSourcesChain.from_chain_type(
        ChatOpenAI(temperature=0.8,
                   streaming=True,
                   chain_type="stuff",
                   retriever=docsearch.as_retriever(max_tokens_limit=4097)
                   )
        )

gives: 07:08:22 pm

Processing 2308.07037.pdf...

Error

07:08:22 pm

[Errno 13] Permission denied: 'C:\Users\tanma\AppData\Local\Temp\tmpkgtc4us6'

TanmayDoesAI avatar Aug 19 '23 13:08 TanmayDoesAI

I think the problem is about python temp files on windows. You can avoid using temp files. Also would be helpful to search if there is a clean solution for this

willydouhard avatar Aug 21 '23 05:08 willydouhard

Yes, it is the problem of Python writing to Temp directory. I had the code like below:

with tempfile.NamedTemporaryFile() as tempfile: tempfile.write(file.content) loader = Loader(tempfile.name)

It was giving Permission Denied error. I replaced with as below and it worked,

with open('filename.ext', 'wb') as file_output: file_output.write(file.content) loader = Loader('filename.ext')

brahmapsen avatar Oct 29 '23 03:10 brahmapsen