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

Error mesage: 'int' object has no attribute 'items' when run example code #2247

Closed
leakedby opened this issue Dec 27, 2023 · 13 comments · Fixed by #2249
Closed

Error mesage: 'int' object has no attribute 'items' when run example code #2247

leakedby opened this issue Dec 27, 2023 · 13 comments · Fixed by #2249
Labels
bug Something isn't working
Milestone

Comments

@leakedby
Copy link

Description

Python version: 3.12.1 with virtualenv
NiceGUI version: latest

I got error message: 'int' object has no attribute 'items'.
When run example code from home page.
Tried downgrade version but still got error message.

Code:

from nicegui import ui

ui.label('Hello NiceGUI!')

ui.run()

Error message:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/james/HelloW/Crawl/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 435, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/james/HelloW/Crawl/.venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/james/HelloW/Crawl/.venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/james/HelloW/Crawl/.venv/lib/python3.12/site-packages/starlette/applications.py", line 116, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/james/HelloW/Crawl/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 176, in __call__
    response = await self.handler(request, exc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/james/HelloW/Crawl/.venv/lib/python3.12/site-packages/nicegui/nicegui.py", line 142, in _exception_handler_500
    return client.build_response(request, 500)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/james/HelloW/Crawl/.venv/lib/python3.12/site-packages/nicegui/client.py", line 119, in build_response
    return templates.TemplateResponse('index.html', {
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/james/HelloW/Crawl/.venv/lib/python3.12/site-packages/starlette/templating.py", line 224, in TemplateResponse
    return _TemplateResponse(
           ^^^^^^^^^^^^^^^^^^
  File "/Users/james/HelloW/Crawl/.venv/lib/python3.12/site-packages/starlette/templating.py", line 39, in __init__
    super().__init__(content, status_code, headers, media_type, background)
  File "/Users/james/HelloW/Crawl/.venv/lib/python3.12/site-packages/starlette/responses.py", line 38, in __init__
    self.init_headers(headers)
  File "/Users/james/HelloW/Crawl/.venv/lib/python3.12/site-packages/starlette/responses.py", line 57, in init_headers
    for k, v in headers.items()
                ^^^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'items'
@rodja
Copy link
Member

rodja commented Dec 27, 2023

Could you share the full exception stack? The message "During handling of the above exception, another exception occurred" hints for something else going on.

@rodja
Copy link
Member

rodja commented Dec 27, 2023

You also cross-posted on Reddit and StackOverflow if I'm not mistaken.

@falkoschindler falkoschindler added the question Further information is requested label Dec 27, 2023
@DavidLeBonk
Copy link

Could you share the full exception stack? The message "During handling of the above exception, another exception occurred" hints for something else going on.

https://discord.com/channels/1089836369431498784/1189464339007156236/1189464339007156236

I had the same error and in the attached message I have a .txt attached with a full traceback

@DavidLeBonk
Copy link

a .txt attached with a full traceback

Here is the txt in question so yall don't gotta hop platforms

traceback.txt

@falkoschindler
Copy link
Contributor

Thanks a lot, @DavidLeBonk!
It would be interesting to bisect since which NiceGUI version the error occurs. The traceback mentions the TemplateResponse, but I don't recall recent changes to the templating implementation. 🤔

@DavidLeBonk
Copy link

Wishing ya the best 👍

@falkoschindler
Copy link
Contributor

Yes! I found the root cause of the problem:
The API for Starlette's templates.TemplateResponse() introduced a new positional argument request (see encode/starlette#2191). This causes our status code to be interpreted as headers dictionary, which fails.

@falkoschindler falkoschindler added bug Something isn't working and removed question Further information is requested labels Dec 27, 2023
@falkoschindler falkoschindler added this to the 1.4.8 milestone Dec 27, 2023
@DavidLeBonk
Copy link

Ah, who doesn't love it when a child library changes something seemingly small and it breaks the everything.

npm moment

@DavidLeBonk
Copy link

Also @falkoschindler should I delete the discord post now to avoid clutter?

@falkoschindler
Copy link
Contributor

@DavidLeBonk No, I think it's good to keep a reference to this issue so that other users can find it more easily.

@falkoschindler
Copy link
Contributor

I noticed that the change in Starlette wasn't an issue, because FastAPI required an older version. Just last night FastAPI 0.108.0 was released, upgrading to Starlette >=0.29.0,<0.33.0.

I already tried adding the request argument, but then there are other exceptions popping up.

@rodja
Copy link
Member

rodja commented Dec 27, 2023

We just released 1.4.8 with the needed fix.

@DavidLeBonk
Copy link

Nice, love to see the quick fixes ^-^

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

Successfully merging a pull request may close this issue.

4 participants