Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to get ticker '<Tickername>' reason: Expecting value: line 1 column 1 (char 0) #2179

Open
rajanpanchal opened this issue Dec 14, 2024 · 12 comments

Comments

@rajanpanchal
Copy link

Describe bug

when downloading tickers I am seeing "Failed to get ticker 'AXON' reason: Expecting value: line 1 column 1 (char 0)" . Only some tickers are successful rest all failing with same error. I have checked these tickers exists at finance.yahoo.com

Simple code that reproduces your problem

` data = yf.download(tickers, period='6mo', interval='1wk', auto_adjust=True, progress=True)```

Debug log

Failed to get ticker 'RSG' reason: Expecting value: line 1 column 1 (char 0)
[**********************94%********************   ]  811 of 860 completedFailed to get ticker 'TSM' reason: Expecting value: line 1 column 1 (char 0)
[**********************94%********************   ]  812 of 860 completedFailed to get ticker 'SPG' reason: Expecting value: line 1 column 1 (char 0)
[**********************95%*********************  ]  813 of 860 completedFailed to get ticker 'CSX' reason: Expecting value: line 1 column 1 (char 0)
[**********************95%*********************  ]  814 of 860 completedFailed to get ticker 'MTB' reason: Expecting value: line 1 column 1 (char 0)
Failed to get ticker 'BHP' reason: Expecting value: line 1 column 1 (char 0)
[**********************96%*********************  ]  827 of 860 completedFailed to get ticker 'INTC' reason: Expecting value: line 1 column 1 (char 0)
[**********************96%*********************  ]  828 of 860 completedFailed to get ticker 'TRI' reason: Expecting value: line 1 column 1 (char 0)
[**********************97%********************** ]  831 of 860 completedFailed to get ticker 'UMC' reason: Expecting value: line 1 column 1 (char 0)
Failed to get ticker 'DOW' reason: Expecting value: line 1 column 1 (char 0)
[**********************97%********************** ]  837 of 860 completedFailed to get ticker 'ELV' reason: Expecting value: line 1 column 1 (char 0)
Failed to get ticker 'CPNG' reason: Expecting value: line 1 column 1 (char 0)

Bad data proof

image

yfinance version

0.1.62

Python version

3

Operating system

windows 11

@ValueRaider
Copy link
Collaborator

Re-run with yf.enable_debug_mode() at start

@R5dan
Copy link
Contributor

R5dan commented Dec 16, 2024

@rajanpanchal I managed to get it working if you specify start and end times explicitly. Something like this:

import yfinance as yf
import datetime as dt

end=dt.datetime.now()

if end.month<=6:
    start = end.replace(year=end.year-1, month=12+(end.month-6))
else:
    start = end.replace(month=end.month-6)

data = yf.download("AXON", interval='1wk', end=end, start=start)

The error seems to be with the yahoo finance api itself as I can't get any stock data for anything with interval='1wk' and setting period.

@Utetsu
Copy link

Utetsu commented Dec 21, 2024

I face the same issue and by specifying the start and end dates doesn't help unfortunately.
My sample code looks like below:
all_price = yf.download(tickers=ticker_list, interval="1d", start="2024-10-03", end="2024-10-04")

My ticker list includes all listed companies in Japan and this line of code used to work back in October 2nd.
Does anyone know how to fix?

@R5dan
Copy link
Contributor

R5dan commented Dec 21, 2024

all listed companies in Japan

Can you specify all the tickers in japan? Or at least where you define them

Can you also do what value raider said and run it with yf.enable_debug_mode at the start of the program. @Utetsu

@Utetsu
Copy link

Utetsu commented Dec 21, 2024

@R5dan Let me share the entire code and my ticker list.
I'm running with yf.enable_debug_mode now but it would take more than 30 mins to execute.
(I'm running thru Google Colab)

import yfinance as yf
import pandas as pd
import numpy as np

yf.enable_debug_mode()

jp_tic = pd.read_excel('/content/drive/MyDrive/Colab Notebooks/ticker_name.xlsx', header=None)
jp_tic[0] = jp_tic[0].apply(str)
jp_tic[0] = [x + '.T' for x in jp_tic[0]]
jp_tic = jp_tic[0].tolist()

all_price = yf.download(tickers=jp_tic, interval="1d", start="2024-10-03", end="2024-10-04")

ticker_name.xlsx

@R5dan
Copy link
Contributor

R5dan commented Dec 21, 2024

jp_tic[0] = [x + '.T' for x in jp_tic[0]]

#2052: The error is you can't have a . in the ticker name.

@Utetsu
Copy link

Utetsu commented Dec 21, 2024

Hi @R5dan
Unlike US ticker, for Asia ticker you need to specify
E.g. 2330 can be

  1. 2330.TW --> TSMC in Taiwan
  2. 2330.HK --> HK listed company China Uptown Group
  3. 2330.T --> Forside in Japan

@R5dan
Copy link
Contributor

R5dan commented Dec 21, 2024

@Utetsu yfinance sends the request to here for TSMC. In my testing, I found that when expanding the day time from 01 to 10 it returns data for most of the days - excluding 03. October 3 is a market holiday so yahoo can't get any data for it and so returns nothing. Leading to your error. The bug I was talking about before seems to be resolved now though.

@R5dan
Copy link
Contributor

R5dan commented Dec 21, 2024

All the others seem to return data

@tbarnette70
Copy link

This is a weird one.. I was getting it a lot and reverted to finance 0.25.0 and get it less frequently. I can rerun the exact same batch and will get it at different times. I almost wonder if it's yahoo throttling of some sort..

I download in batches of 11 and it will get the error message for a while and I will restart and it will get to an entirely different set of stickers and the error comes back. I specified the start date and end date explicitly as mentioned above and that seemed to make it a bit better.

11 Failed downloads:
['OPEN', 'USPH', 'ETV', 'MSFT', 'STER', 'BANR', 'HG', 'POWL', 'EXPI', 'LILA', 'SGML']: JSONDecodeError('Expecting value: line 1 column 1 (char 0)')

Are other people still getting this error message?

@carles2m
Copy link

I may be wrong; this is what I found - workaround on the last paragraph:

I ran this with yf.enable_debug_mode and did some debugging and I believe the code is doing is 2 request for each symbol:

  1. Request for the timezone
  2. Request for the data

What I think is happening is:

  • When a 429 (Too many requests - aka throttling) is returned on the 2nd request, yfinance handles that correctly and raises a RequestException (I pass raise_errors=True and retry the request in this case).
  • However, when the 429 happens during the 1st request, yfinance doesn't correctly handle the data returned in the 429 and prints the JSON error, and in the process raises a YFTickerMissingError (which is incorrect, should be some RequestException).

The workaround that is working for me is to not pass a start and specify a period different than max so yfinance doesn't make the (incorrectly handled) timezone request. This has the caveat that only the last minute, day, etc. can be queried.

@ValueRaider
Copy link
Collaborator

(incorrectly handled) timezone request

I've just now fixed this in dev branch. You get a rate-limit exception.

I pass raise_errors=True and retry the request in this case

Another change in dev means that for the 429 error, it is always raised regardless of raise_errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants