Troubleshooting
Solutions to common issues when using StakeAPI.
π‘ Don't have a Stake.com account yet? Sign up here to get started and unlock all API features.
Authentication Issues
AuthenticationError: Invalid access token
Cause: Your access token is invalid or has expired.
Solution:
- Log in to Stake.com in your browser
- Open Developer Tools β Network tab
- Find a request to
/_api/graphql - Copy the fresh
x-access-tokenvalue
# Check if token is valid format
from stakeapi.utils import validate_api_key
print(validate_api_key(your_token)) # Should be True
Token works in browser but not in Python
Cause: Token may have been invalidated after you logged out, or headers are missing.
Solution: Ensure youβre passing the token correctly:
# β
Correct
client = StakeAPI(access_token="your_actual_token_value")
# β Wrong β don't include the header name
client = StakeAPI(access_token="x-access-token: token_value")
Connection Issues
NetworkError: Request failed
Cause: Cannot connect to Stake.com servers.
Solutions:
- Check your internet connection
- Verify Stake.com is accessible from your location
- Check if youβre behind a firewall/proxy
- Try increasing the timeout:
client = StakeAPI(access_token="token", timeout=60)
Connection timeout
Cause: Request took too long.
Solution: Increase timeout:
client = StakeAPI(access_token="token", timeout=120)
Rate Limiting
RateLimitError: Rate limit exceeded
Cause: Too many requests too quickly.
Solution: Add delays between requests:
import asyncio
# Add delay between requests
for game_id in game_ids:
game = await client.get_game_details(game_id)
await asyncio.sleep(0.5) # 500ms delay
Or use exponential backoff:
async def fetch_with_backoff(func, max_retries=3):
for i in range(max_retries):
try:
return await func()
except RateLimitError:
await asyncio.sleep(2 ** i)
raise Exception("Max retries exceeded")
Import Issues
ModuleNotFoundError: No module named 'stakeapi'
Solution:
pip install stakeapi
If using a virtual environment, make sure itβs activated:
# Windows
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activate
ImportError: cannot import name 'StakeAPI'
Solution: Check your import statement:
# β
Correct
from stakeapi import StakeAPI
# β Wrong
from stakeapi.client import StakeAPI # Also works but not recommended
Async Issues
RuntimeError: no running event loop
Cause: Using async code without an event loop.
Solution: Use asyncio.run():
import asyncio
async def main():
async with StakeAPI(access_token="token") as client:
balance = await client.get_user_balance()
# β
Correct
asyncio.run(main())
# β Wrong β don't call async functions directly
# main() # This returns a coroutine, not the result
RuntimeWarning: coroutine was never awaited
Cause: Forgetting to await an async call.
# β Wrong
balance = client.get_user_balance() # Missing await!
# β
Correct
balance = await client.get_user_balance()
RuntimeError: Session is closed
Cause: Using the client after the context manager has exited.
# β Wrong
async with StakeAPI(access_token="token") as client:
pass
# Client is closed here!
balance = await client.get_user_balance()
# β
Correct β keep operations inside the context
async with StakeAPI(access_token="token") as client:
balance = await client.get_user_balance()
Data Issues
Empty results from API calls
Possible causes:
- Account has no data (new account with no bets)
- Filter parameters are too restrictive
- API endpoint returned unexpected format
Solution: Try without filters first:
# Try without category filter
games = await client.get_casino_games() # No filter
print(f"Total games: {len(games)}")
Pydantic validation errors
Cause: API returned unexpected data format.
Solution: Use raw GraphQL to inspect the response:
data = await client._graphql_request(
query="query { user { id name } }"
)
print(data) # Inspect raw response
Platform-Specific Issues
Windows: ProactorEventLoop warnings
Add this at the top of your script:
import asyncio
import sys
if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
Jupyter Notebook: Event loop already running
Use nest_asyncio:
import nest_asyncio
nest_asyncio.apply()
import asyncio
from stakeapi import StakeAPI
async def main():
async with StakeAPI(access_token="token") as client:
return await client.get_user_balance()
balance = asyncio.run(main())
Still Stuck?
- Check the FAQ
- Search GitHub Issues
- Open a new issue with:
- StakeAPI version
- Python version
- Full error traceback
- Minimal reproducing code
π¬ Join the StakeAPI Community on Discord
Get help, share your projects, discuss strategies, and stay up to date with the latest StakeAPI news.
Join Our Discord Server βMost issues are solved by getting a fresh access token. Sign up on Stake.com and grab a new token from Developer Tools.