Skip to content
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

[BUG]: upload note return server internal error #24

Closed
zephyrpathsofglory opened this issue Sep 2, 2023 · 14 comments
Closed

[BUG]: upload note return server internal error #24

zephyrpathsofglory opened this issue Sep 2, 2023 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@zephyrpathsofglory
Copy link

Description of the bug

I uploaded a md file but the server returned 500, and the following is the log of server:

INFO:     192.168.228.4:48302 - "POST /note HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 289, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/usr/local/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in __call__
    raise e
  File "/usr/local/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in __call__
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 273, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 190, in run_endpoint_function
    return await dependant.call(**values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/main.py", line 63, in add_note
    return await _apis_.note.add_note(language, questionType, noteName, files, notionId)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/apis/note.py", line 62, in add_note
    if (len(files) > 3):
        ^^^^^^^^^^
TypeError: object of type 'NoneType' has no len()

Environment:

Macos 14 Beta, M1 chip
OpenAI Key with API_BASE setup
@zephyrpathsofglory zephyrpathsofglory added the bug Something isn't working label Sep 2, 2023
@codeacme17
Copy link
Owner

@zephyrpathsofglory, Have you made sure you passed in the file? If possible, can you send me the request body so that I can better locate the error. Thanks your issue!

@zephyrpathsofglory
Copy link
Author

@zephyrpathsofglory, Have you made sure you passed in the file? If possible, can you send me the request body so that I can better locate the error. Thanks your issue!

This is the request body:
Screenshot 2023-09-02 at 16 36 02

It seems that my file has not uploaded?

@zephyrpathsofglory
Copy link
Author

Screenshot 2023-09-02 at 16 40 30

It is weird that it shows only .md type files are allowed to be uploaded but what I uploaded is a md file.

@codeacme17
Copy link
Owner

This is the request body: Screenshot 2023-09-02 at 16 36 02

It seems that my file has not uploaded?

Yes you are not passing file in your request body. I'm curious how this happens, because in the front-end form, the upload button cannot be clicked without selecting a file.

@codeacme17
Copy link
Owner

codeacme17 commented Sep 2, 2023

You can try to pull the latest code, and then try to upload note to see if this happens again. it's really weird.

@zephyrpathsofglory
Copy link
Author

I have pulled the latest code, rebuilt the docker images, and restarted the docker-compose servers. But still got the same error.

@codeacme17
Copy link
Owner

codeacme17 commented Sep 2, 2023

I have pulled the latest code, rebuilt the docker images, and restarted the docker-compose servers. But still got the same error.

okay, I think the problem should be in the frontend, give me some time to find where the problem is.

@codeacme17
Copy link
Owner

codeacme17 commented Sep 2, 2023

@zephyrpathsofglory, hi, I should know what the problem is, is the MIME type of the file you uploaded text/markdown or text/x-markdown? It will report an error if you don't upload the exact file type. Of course I'm sorry for not terminating subsequent operations when uploading the wrong file.

@zephyrpathsofglory
Copy link
Author

The uploaded file is a README file with md extension downloaded from github. The mime type of this file is text/html(get by executing file --mime-type -b $file)

@codeacme17
Copy link
Owner

codeacme17 commented Sep 2, 2023

Yeah its not allowed. detectLegalFile You can see the logic in this code. I have modified the logic of not terminating the upload after reporting an error and will update it immediately.

codeacme17 added a commit that referenced this issue Sep 2, 2023
…loading the wrong file type [BUG]: upload note return server internal error #24
codeacme17 added a commit that referenced this issue Sep 2, 2023
fix: fixed an issue where the upload event was not terminated when uploading the wrong file type #24
@zephyrpathsofglory
Copy link
Author

Yeah its not allowed. detectLegalFile You can see the logic in this code. I have modified the logic of not terminating the upload after reporting an error and will update it immediately.

Why not check file type by file extensions?

@codeacme17
Copy link
Owner

Yeah its not allowed. detectLegalFile You can see the logic in this code. I have modified the logic of not terminating the upload after reporting an error and will update it immediately.

Why not check file type by file extensions?

Because MIME types provide more accurate information about the file's content, are more secure, have better cross-platform compatibility, and are less susceptible to manipulation by malicious users.

@zephyrpathsofglory
Copy link
Author

zephyrpathsofglory commented Sep 2, 2023

Yeah its not allowed. detectLegalFile You can see the logic in this code. I have modified the logic of not terminating the upload after reporting an error and will update it immediately.

Why not check file type by file extensions?

Because MIME types provide more accurate information about the file's content, are more secure, have better cross-platform compatibility, and are less susceptible to manipulation by malicious users.

Thank you, but not all md file is text/markdown. It will fail the upload with a good chance.

@codeacme17
Copy link
Owner

What you said is correct. I will add more type judgments after trying it later. Thank you very much for your issue and follow! If you have any suggestions in the future, you can also submit an issue or PR ~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants