What I’m trying to do:
I am attempting to create a dashboard that pulls in and displays a variety of NBA data. I am using the nba_api Python package to accomplish this. All code has been tested locally and works, but the calls are timing out.
What I’ve tried and what’s not working:
I’ve installed nba_api onto the server through PyPi. I’ve tried making the calls a background task in addition to obviously already having them in a server module and not the client code. Whether its a background task or not, it will ultimately fail on a timeout. Any ideas as to why this is happening? I am new to Anvil so hoping I’m just making a rookie mistake and its not something to do with the package (nba_api is listed as supported on Anvil)
When the function is a regular callable, the error is: anvil.server.TimeoutError: Server code took too long
Code Sample:
games = anvil.server.call('getScoreboard')
for game in games:
b = Button(text=game, tag=game[0:2])
self.linear_panel.add_component(b)
b.set_event_handler('click', self.click_handler)``
@anvil.server.callable
def getScoreboard():
print("Entering getScoreboard...")
temp = scoreboardv2.ScoreboardV2().get_dict()
print("Scoreboard acquired...")
matchups = []
for i in range(0, (len(temp["resultSets"][1]["rowSet"]) // 2)):
matchups.append(temp["resultSets"][1]["rowSet"][2*i][4] + ' vs. ' + temp["resultSets"][1]["rowSet"][(2*i)+1][4])
return matchup
Note that I never reach the second print on my testing, so it is assuredly failing on the api call
Clone link:
https://anvil.works/build#clone:YHMCR3SMRGGGQPF4=LPBCM43YRKP4DVJAXNUUPY4C