THE SAME CODE WHICH WAS RUNNING FOR PAST WEEK SUGGESTING ERROR AND AI IS TELLING ME THIS :---- Where in your code would this happen?
The most likely culprits are:
tsl.ATM_Strike_Selection('BANKNIFTY', 0)
:
- If
tsl.ATM_Strike_Selection
fails to find valid ATM strikes, it might returnNone
force_strike_symbol
orpe_strike_symbol
. - Your code already has a check for this: `Pythonif ce_strike_symbol is None or pe_strike_symbol is None:
print(f"{Fore.RED}ERROR: Could not determine ATM strikes using Tradehull. Skipping this cycle.{Style.RESET_ALL}")… (sleep and continue)
continueThis check is good and should prevent the error if
ATM_Strike_Selectionitself returns
None`.
tsl.get_historical_data(ce_strike_symbol, 'NFO', CHART_INTERVAL)
:
- This is the most probable cause.
- The error message in your output explicitly states: “Fetching historical data for BANKNIFTY 26 JUN 55600 CALL (CE) and BANKNIFTY 26 JUN 55600 PUT (PE) using Tradehull on 25 min chart…” followed by the
PROCESSING_ERROR
. - This strongly suggests that the
get_historical_data
method inside yourTradehull
class (which is not provided in this snippet) returnedNone
. - When
ce_chart_raw
(orpe_chart_raw
) becomesNone
, the subsequent lines of code within thetry
block for processing that data, which assumece_chart_raw
is a DataFrame (or at least an object with a.name
attribute if some internalpandas
oropenpyxl
logic is being used before column access), will fail. - For example, if somewhere in your
Tradehull
class’sget_historical_data
method, it attempts to get the.name
attribute of aNone
object (perhaps if a response from the Dhan API is empty or malformed and results in aNone
DataFrame), then that specific error would propagate.
Why the Error “There is no item named ‘[Content_Types].xml’ in the archive” also appeared earlier:
The earlier Excel-related error, KeyError: "There is no item named '[Content_Types].xml' in the archive"
, is a separate issue that likely occurred because of the preceding data fetching failure.
When tsl.get_historical_data
returns None
or an empty DataFrame, your script might still attempt to write to the Excel file. If df_ce_calculated
or pe_df_calculated
ends up being None
or an invalid DataFrame, the to_excel
call could then fail, especially if the writer
object (which uses openpyxl
) tries to open a corrupted or improperly closed Excel file from a previous error.
To pinpoint the exact line for 'NoneType' object has no attribute 'name'
, you need to debug the Tradehull
class itself, specifically get_historical_data
.
What to do (without changing your provided code):
Since you explicitly said “donot change the single line of the code,” you need to understand that the root cause is external to this exact script snippet but within the Tradehull
library you are using.
The problem originates from how Tradehull
handles failed API responses. It appears that tsl.get_historical_data
is returning None
instead of, for instance, an empty DataFrame, or raising a more specific error that indicates “no data found for this symbol/interval.”
Hypothesis:
The get_historical_data
method within your Dhan_Tradehull_V2.py
file (or wherever Tradehull
is defined) is failing to retrieve data and, as a result, is returning None
. Subsequently, when your main script attempts to process this None
object as if it were a Pandas DataFrame, it encounters the 'NoneType' object has no attribute 'name'
error. This usually happens when a function expects a specific type of object (like a DataFrame) but gets None
instead.
Recommendation (if you could modify Dhan_Tradehull_V2.py
):
The ideal fix would be to modify the Tradehull
class’s get_historical_data
method (and potentially ATM_Strike_Selection
) to:
- Return an empty DataFrame if no data is found or an API call fails, instead of
None
. This makes subsequent DataFrame operations more robust. - Raise specific exceptions (e.g.,
TradehullAPIError
,NoDataFoundError
) when an API call fails or no data is available, allowing for more granular error handling in your main script.
Since you cannot change the code:
You’ll need to recognize that the Tradehull
library is failing to provide the data. This might be due to:
- Invalid
client_code
ortoken_id
: Double-check these are correct. - Tradehull/Dhan API issues: The service might be down, rate-limiting you, or having temporary glitches.
- Incorrect symbol/exchange parameters: Though unlikely if it worked previously, ensure
BANKNIFTY 26 JUN 55500 CALL
(which is determined byATM_Strike_Selection
) is a valid and tradable symbol on the ‘NFO’ exchange for the25
minute interval at this exact time.
Given the time (09:25 AM IST), the market is open, so it’s not a pre-market or post-market issue. The “No historical data available” warning from your code correctly identifies that ce_chart_raw
or pe_chart_raw
is None
or empty. The PROCESSING_ERROR
that follows suggests that the Exception as e
caught a deeper error within that NoneType
path before it could correctly print NO_DATA_API
.