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
¿Cómo puedo hacer para manejar el siguiente dato recogido de un request?
[
{
"id": 1037653,
"date": "2023-11-01T00:00:00.000Z",
"home_team": {
"id": 21,
"abbreviation": "OKC",
"city": "Oklahoma City",
"conference": "West",
"division": "Northwest",
"full_name": "Oklahoma City Thunder",
"name": "Thunder"
},
"home_team_score": 106,
"period": 4,
"postseason": false,
"season": 2023,
"status": "Final",
"time": "Final",
"visitor_team": {
"id": 19,
"abbreviation": "NOP",
"city": "New Orleans",
"conference": "West",
"division": "Southwest",
"full_name": "New Orleans Pelicans",
"name": "Pelicans"
},
"visitor_team_score": 110
}
]
Mi codigo state es el siguiente:
import reflex as rx
import datetime
import locale
import requests
from typing import List,Union,Dict
Establecer el idioma local a ingles
locale.setlocale(locale.LC_TIME, 'en_US.utf8')
class State(rx.State):
#inicializamos
diaHoy = datetime.date.today()
date = diaHoy
#request a la api
match = "https://www.balldontlie.io/api/v1/games?dates[]="+ str(date)
diccionario: List[dict] = requests.get(match).json()['data']
#para imprimir el dia bonito
dayClean = date.strftime("%A %B %d, %Y")
import requests
import reflex as rx
from NBA_API.styles.color import Colors as Color
from NBA_API.styles.font import Fonts as Font
from NBA_API.components.match_box import match_box
from NBA_API.state import State
from typing import List, Dict
#recorre todos los partidos
def stats_matches():
return rx.responsive_grid(
rx.foreach(
State.diccionario,
display_box
),
columns=[1],
spacing="4",
width="100%"
)
No entiendo por qué me sale el siguiente error:
Process SpawnProcess-2:
Traceback (most recent call last):
File "C:\Program Files\Python311\Lib\multiprocessing\process.py", line 314, in _bootstrap
self.run()
File "C:\Program Files\Python311\Lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\uvicorn_subprocess.py", line 76, in subprocess_started
target(sockets=sockets)
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\uvicorn\server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\asyncio\runners.py", line 190, in run return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\asyncio\runners.py", line 118, in run return self.loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\uvicorn\server.py", line 67, in serve
config.load()
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\uvicorn\config.py", line 477, in load
self.loaded_app = import_from_string(self.app)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\importlib_init.py", line 126, in
import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1206, in _gcd_import
File "", line 1178, in _find_and_load
File "", line 1149, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in _call_with_frames_removed
File "C:\Users\SANTI\Documents\PROJECTOS\NBA-API\NBA_API\NBA_API.py", line 38, in
app.add_page(index)
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\reflex\app.py", line 385, in add_page
component = self._generate_component(component)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\reflex\app.py", line 337, in _generate_component
raise e
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\reflex\app.py", line 328, in _generate_component
return component if isinstance(component, Component) else component()
^^^^^^^^^^^
File "C:\Users\SANTI\Documents\PROJECTOS\NBA-API\NBA_API\NBA_API.py", line 27, in index
stats_matches(),
^^^^^^^^^^^^^^^
File "C:\Users\SANTI\Documents\PROJECTOS\NBA-API\NBA_API\logica\stats.py", line 26, in stats_matches
rx.foreach(
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\reflex\components\layout\foreach.py", line 53, in create
children=[IterTag.render_component(render_fn, arg=arg)],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\reflex\components\tags\iter_tag.py", line 73, in render_component
component = render_fn(arg)
^^^^^^^^^^^^^^
File "C:\Users\SANTI\Documents\PROJECTOS\NBA-API\NBA_API\logica\stats.py", line 13, in display_box
header = rx.heading(f"{game['home_team']['full_name']} vs {game['visitor_team']['full_name']}"),
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\reflex\vars.py", line 282, in getitem
raise TypeError(
TypeError: Could not index into var of type Any. (If you are trying to index into a state var, add the correct type annotation to the var.)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
¿Cómo puedo hacer para manejar el siguiente dato recogido de un request?
[
{
"id": 1037653,
"date": "2023-11-01T00:00:00.000Z",
"home_team": {
"id": 21,
"abbreviation": "OKC",
"city": "Oklahoma City",
"conference": "West",
"division": "Northwest",
"full_name": "Oklahoma City Thunder",
"name": "Thunder"
},
"home_team_score": 106,
"period": 4,
"postseason": false,
"season": 2023,
"status": "Final",
"time": "Final",
"visitor_team": {
"id": 19,
"abbreviation": "NOP",
"city": "New Orleans",
"conference": "West",
"division": "Southwest",
"full_name": "New Orleans Pelicans",
"name": "Pelicans"
},
"visitor_team_score": 110
}
]
Mi codigo state es el siguiente:
import reflex as rx
import datetime
import locale
import requests
from typing import List,Union,Dict
Establecer el idioma local a ingles
locale.setlocale(locale.LC_TIME, 'en_US.utf8')
class State(rx.State):
#inicializamos
diaHoy = datetime.date.today()
date = diaHoy
#request a la api
match = "https://www.balldontlie.io/api/v1/games?dates[]="+ str(date)
diccionario: List[dict] = requests.get(match).json()['data']
#para imprimir el dia bonito
dayClean = date.strftime("%A %B %d, %Y")
import requests
import reflex as rx
from NBA_API.styles.color import Colors as Color
from NBA_API.styles.font import Fonts as Font
from NBA_API.components.match_box import match_box
from NBA_API.state import State
from typing import List, Dict
def display_box(game):
return rx.card(
rx.text(f"{game['home_team_score']} vs {game['visitor_team_score']}"),
header = rx.heading(f"{game['home_team']['full_name']} vs {game['visitor_team']['full_name']),
footer = rx.hstack(
rx.icon(
tag="star"
)
),
align="center",
width="100%"
)
#recorre todos los partidos
def stats_matches():
return rx.responsive_grid(
rx.foreach(
State.diccionario,
display_box
),
columns=[1],
spacing="4",
width="100%"
)
No entiendo por qué me sale el siguiente error:
Process SpawnProcess-2:
Traceback (most recent call last):
File "C:\Program Files\Python311\Lib\multiprocessing\process.py", line 314, in _bootstrap
self.run()
File "C:\Program Files\Python311\Lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\uvicorn_subprocess.py", line 76, in subprocess_started
target(sockets=sockets)
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\uvicorn\server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\asyncio\runners.py", line 190, in run return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\asyncio\runners.py", line 118, in run return self.loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\uvicorn\server.py", line 67, in serve
config.load()
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\uvicorn\config.py", line 477, in load
self.loaded_app = import_from_string(self.app)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\importlib_init.py", line 126, in
import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1206, in _gcd_import
File "", line 1178, in _find_and_load
File "", line 1149, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in _call_with_frames_removed
File "C:\Users\SANTI\Documents\PROJECTOS\NBA-API\NBA_API\NBA_API.py", line 38, in
app.add_page(index)
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\reflex\app.py", line 385, in add_page
component = self._generate_component(component)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\reflex\app.py", line 337, in _generate_component
raise e
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\reflex\app.py", line 328, in _generate_component
return component if isinstance(component, Component) else component()
^^^^^^^^^^^
File "C:\Users\SANTI\Documents\PROJECTOS\NBA-API\NBA_API\NBA_API.py", line 27, in index
stats_matches(),
^^^^^^^^^^^^^^^
File "C:\Users\SANTI\Documents\PROJECTOS\NBA-API\NBA_API\logica\stats.py", line 26, in stats_matches
rx.foreach(
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\reflex\components\layout\foreach.py", line 53, in create
children=[IterTag.render_component(render_fn, arg=arg)],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\reflex\components\tags\iter_tag.py", line 73, in render_component
component = render_fn(arg)
^^^^^^^^^^^^^^
File "C:\Users\SANTI\Documents\PROJECTOS\NBA-API\NBA_API\logica\stats.py", line 13, in display_box
header = rx.heading(f"{game['home_team']['full_name']} vs {game['visitor_team']['full_name']}"),
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "C:\Users\SANTI\AppData\Roaming\Python\Python311\site-packages\reflex\vars.py", line 282, in getitem
raise TypeError(
TypeError: Could not index into var of type Any. (If you are trying to index into a state var, add the correct type annotation to the var.)
Beta Was this translation helpful? Give feedback.
All reactions