You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use the pc.upload() and when add a pc.buttton() that on_click will call an other function that takes in pc.upload_files() but when selecting a file and clicking on upload, i get the following exception:
──────────── Starting Pynecone App ─────────────
───────── Installing frontend packages ─────────
bun install v0.5.5 (242dcea2)
───────────────── App Running ──────────────────
$ next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
event - compiled client and server successfully in 1041 ms (757 modules)
wait - compiling...
event - compiled client and server successfully in 144 ms (757 modules)
wait - compiling /404 (client and server)...
event - compiled client and server successfully in 123 ms (761 modules)
warn - Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/basic-features/fast-refresh#how-it-works
wait - compiling / (client and server)...
event - compiled client and server successfully in 264 ms (904 modules)
warn - Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/basic-features/fast-refresh#how-it-works
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/home/ramsy/.local/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 419, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "/home/ramsy/.local/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
return await self.app(scope, receive, send)
File "/home/ramsy/.local/lib/python3.10/site-packages/fastapi/applications.py", line 270, in __call__
await super().__call__(scope, receive, send)
File "/home/ramsy/.local/lib/python3.10/site-packages/starlette/applications.py", line 124, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/ramsy/.local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__
raise exc
File "/home/ramsy/.local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
await self.app(scope, receive, _send)
File "/home/ramsy/.local/lib/python3.10/site-packages/starlette/middleware/cors.py", line 92, in __call__
await self.simple_response(scope, receive, send, request_headers=headers)
File "/home/ramsy/.local/lib/python3.10/site-packages/starlette/middleware/cors.py", line 147, in simple_response
await self.app(scope, receive, send)
File "/home/ramsy/.local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
raise exc
File "/home/ramsy/.local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
await self.app(scope, receive, sender)
File "/home/ramsy/.local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
raise e
File "/home/ramsy/.local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
await self.app(scope, receive, send)
File "/home/ramsy/.local/lib/python3.10/site-packages/starlette/routing.py", line 706, in __call__
await route.handle(scope, receive, send)
File "/home/ramsy/.local/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
await self.app(scope, receive, send)
File "/home/ramsy/.local/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
response = await func(request)
File "/home/ramsy/.local/lib/python3.10/site-packages/fastapi/routing.py", line 235, in app
raw_response = await run_endpoint_function(
File "/home/ramsy/.local/lib/python3.10/site-packages/fastapi/routing.py", line 161, in run_endpoint_function
return await dependant.call(**values)
File "/home/ramsy/.local/lib/python3.10/site-packages/pynecone/app.py", line 521, in upload_file
or types._issubclass(v, UploadFile)
File "/home/ramsy/.local/lib/python3.10/site-packages/pynecone/utils/types.py", line 113, in _issubclass
return cls_check_base == Any or issubclass(cls_base, cls_check_base)
TypeError: issubclass() arg 1 must be a class
To Reproduce
This is my current implementation of pc.upload():
importpyneconeaspcfromMusBleep.stateimportMusBleepStatedefdragOrDropUpload():
""" Drag or drop to upload form """returnpc.vstack(
pc.upload(
pc.vstack(
pc.button(
"Select File",
color="rgb(107,99,246)",
bg="white",
border=f"1px solid rgb(107,99,246)",
),
pc.text(
"Drag and drop music file here or click to select a music file"
),
),
border=f"1px dotted rgb(107,99,246)",
padding="5em",
),
pc.button(
"Upload",
on_click=lambda: MusBleepState.handle_music_upload(
pc.upload_files()
),
),
)
and this is my app state class:
importrequestsimportpyneconeaspcclassMusBleepState(pc.State):
""" Main state handler for the web app """is_darkMode=Truedefchange_mode(self) ->None:
""" Changes the mode """self.is_darkMode=notself.is_darkMode# Music Uploadbleeped_music_url: str=""music_name: str="Nothing to show"# default valueis_upload_finish: bool=Falseis_music_upload_exception_raised: bool=False# Used to show a warning when the music upload failsis_faild_to_bleep_music_exception_raised: bool=False# Play Music statesis_playing: bool=Falseasyncdefhandle_music_upload(self, file: pc.UploadFile) ->None:
""" Upload the music to the API to get bleeped """API_URL="http://127.0.0.1:9090"MUSIC_CONTENT=awaitfile.read()
MUSIC_NAME=file.filenameprint(MUSIC_NAME)
FILE= {
"file": MUSIC_CONTENT
}
PARAMS= {
"music_name": MUSIC_NAME
}
RESPONCE=requests.post(
f"{API_URL}/api/v1/bleep_music",
files=FILE,
params=PARAMS
)
ifRESPONCE.status_code==409:
self.is_faild_to_bleep_music_exception_raised=TrueelifRESPONCE.status_code==200:
self.bleeped_music_url=f"{API_URL}{RESPONCE.json()['bleeped_music_path']}"defupdate_upload_exception_state(self) ->None:
""" Updates the `is_music_upload_exception_raised` value """self.is_music_upload_exception_raised=notself.is_music_upload_exception_raiseddefupdate_faild_to_bleep_music_exception_state(self) ->None:
""" Updates the `is_faild_to_bleep_music_exception_raised` value """self.is_faild_to_bleep_music_exception_raised=notself.is_faild_to_bleep_music_exception_raiseddefupdate_playing_state(self) ->None:
""" Updates the `is_playing` value """self.is_playing=notself.is_playing
Note that when calling the function MusBleepState.handle_music_upload(pc.upload_files()) it doesn't get triggered
Python Version: 3.10
Pynecone Version: 1.22
OS: Arch
Browser (Optional): Chrome browser (stable)
The text was updated successfully, but these errors were encountered:
I'm trying to use the
pc.upload()
and when add apc.buttton()
thaton_click
will call an other function that takes inpc.upload_files()
but when selecting a file and clicking on upload, i get the following exception:To Reproduce
This is my current implementation of
pc.upload()
:and this is my app state class:
Note that when calling the function
MusBleepState.handle_music_upload(pc.upload_files())
it doesn't get triggeredThe text was updated successfully, but these errors were encountered: