Python新手求助:Jupyter Notebook执行代码无结果无报错
Hey there! I get it—when code runs without errors but gives no output, it’s super frustrating. Let’s walk through the most common fixes for your nsepy issue:
1. Explicitly Print or Display the Variable
Jupyter Notebook doesn’t automatically output variables assigned with = unless you either:
- Add
print(sbin)at the end of your code block, or - Write just
sbinas a separate line (no assignment) after the code.
Try modifying your code like this:
from datetime import date from nsepy import get_history sbin = get_history(symbol='SBIN', start=date(2015,1,1), end=date(2015,1,10)) # Either print it print(sbin) # Or just call the variable to trigger Jupyter's auto-display sbin
2. Check for Valid Trading Days
January 1, 2015 was a public holiday in India, and the NSE might have been closed on other days in that range too. If your date range only includes non-trading days, get_history will return an empty DataFrame (which looks like "no output" if you don’t explicitly print it).
Try narrowing to a confirmed trading window, like:
sbin = get_history(symbol='SBIN', start=date(2015,1,2), end=date(2015,1,9))
3. Update NSEpy and Dependencies
Older versions of nsepy can break due to changes in the NSE’s API. Run this in a Jupyter cell to upgrade to the latest version:
!pip install --upgrade nsepy pandas requests
This ensures you have compatible versions of all required packages.
4. Enable Debug Logging to Diagnose Connections
If the above steps don’t work, turn on debug logs to see what’s happening under the hood. This will show you if the API request is failing, timing out, or returning empty data:
import logging logging.basicConfig(level=logging.DEBUG) from datetime import date from nsepy import get_history sbin = get_history(symbol='SBIN', start=date(2015,1,1), end=date(2015,1,10)) print(sbin)
The logs will reveal if there’s a connection issue, authentication problem, or API endpoint change.
5. Verify Data Existence Manually
Double-check that SBIN had listed data in your target date range by checking the NSE’s official historical data section. If the data doesn’t exist there, nsepy can’t pull it either.
内容的提问来源于stack exchange,提问作者Rahul Kulkarni

