Exception near "without": syntax error - ticker.fast_info['market_cap']
I want to import 'market_cap' information, but I am getting an error.
Exception near "without": syntax error
check please
Post exact code that reproduces error.
ticker = yf.Ticker('AAPL') print(ticker.fast_info['market_cap'])
Actually, there's more info you need to provide. Read this properly
yf version is 0.2.9
OS: AWS amazon Linux 2.0
- Error message, with traceback if shown
All exceptions generate a traceback. What is confusing about this request?
Full Code 👍
import yfinance as yf import pprint
try:
stock_code = 'AAPL'
print(stock_code, " ..Start.. ")
ticker = yf.Ticker(stock_code)
stock_info2 = ticker.fast_info
print("-------------------------\n")
pprint.pprint(stock_info2)
print("-------------------------\n")
print(stock_info2['last_price'])
print("-------------------------\n")
print(stock_info2['market_cap'])
print("-------------------------\n")
except Exception as e: print("Exception ", e)
Full Log 👍
AAPL ..Start..
lazy-loading dict with keys = ['currency', 'exchange', 'timezone', 'shares', 'market_cap', 'last_price', 'previous_close', 'open', 'day_high', 'day_low', 'regular_market_previous_close', 'last_volume', 'fifty_day_average', 'two_hundred_day_average', 'ten_day_average_volume', 'three_month_average_volume', 'year_high', 'year_low', 'year_change']
145.92999267578125
Exception near "without": syntax error
try:
...
except Exception as e:
print("Exception ", e)
You are deliberately discarding the traceback by doing this. Stop making this difficult.
Oh Sorry.. Error code is
Traceback (most recent call last):
File "/var/autobot/test_i.py", line 20, in
Run this, print output:
import sqlite3
print(sqlite3.sqlite_version)
And what is your Python version?
Python version is Python 3.7.16 sqlite3 version is 3.7.17
So that error message generated by old sqlite bundled in old Python. Can update Python to 3.8?
Alternatively, this branch should fix error: fix/old-sqlite-error. Instructions #1080
Thanks.
I will try both solutions!
I solved it by upgrading the sqlite3 version. thank you!
Hey I am able to run the yfinance API locally, but when I tried running it on Amazon MWAA Airflow I got the same error
My local machine has this configuration python version - 3.10.8 Sqlite3 - 3.37.2
and my Amazon MWAA Airflow configuration is python version - 3.10.8 (main, Jan 17 2023, 22:57:31) [GCC 7.3.1 20180712 (Red Hat 7.3.1-15)] SQLite - 3.7.17
@zacra how did you upgrade the sqlite version, can you please share the steps?
Hey I am able to run the yfinance API locally, but when I tried running it on Amazon MWAA Airflow I got the same error
My local machine has this configuration python version - 3.10.8 Sqlite3 - 3.37.2
and my Amazon MWAA Airflow configuration is python version - 3.10.8 (main, Jan 17 2023, 22:57:31) [GCC 7.3.1 20180712 (Red Hat 7.3.1-15)] SQLite - 3.7.17
@zacra how did you upgrade the sqlite version, can you please share the steps?
Even I am facing the same problem. Not able to use yfinance in AWS Airflow 2.4.3
Hey I am able to run the yfinance API locally, but when I tried running it on Amazon MWAA Airflow I got the same error
My local machine has this configuration python version - 3.10.8 Sqlite3 - 3.37.2
and my Amazon MWAA Airflow configuration is python version - 3.10.8 (main, Jan 17 2023, 22:57:31) [GCC 7.3.1 20180712 (Red Hat 7.3.1-15)] SQLite - 3.7.17
@zacra how did you upgrade the sqlite version, can you please share the steps?
try below command!
pip3 install yfinance --upgrade --no-cache-dir
wget https://kojipkgs.fedoraproject.org//packages/sqlite/3.8.11/1.fc21/x86_64/sqlite-devel-3.8.11-1.fc21.x86_64.rpm wget https://kojipkgs.fedoraproject.org//packages/sqlite/3.8.11/1.fc21/x86_64/sqlite-3.8.11-1.fc21.x86_64.rpm sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm sqlite-devel-3.8.11-1.fc21.x86_64.rpm
@zacra Locally I'm able to update sqlite. Not sure how I will be able to update on AWS Airflow.
@zacra Locally I'm able to update sqlite. Not sure how I will be able to update on AWS Airflow.
Oh I use AWS EC2. I'm not sure how solves this problem on AWS Airflow
Not sure how I will be able to update on AWS Airflow.
You don't need to. PIP pre-release 0.2.10b1 has a fix for older sqlite verison (and dev branch), can anyone confirm fixed?
@ValueRaider
A very simple test
import yfinance as yf
import sqlite3
def test_crawler():
print(yf.version.version)
print(sqlite3.sqlite_version)
y_dict = yf.download(tickers=['7203.T', ], start='2023-01-01', end='2023-02-01',)
print(len(y_dict))
# def
The output
0.2.10b2
3.7.17
[*********************100%***********************] 1 of 1 completed
19
OS is
$ cat /etc/system-release
Amazon Linux release 2 (Karoo)
And, thank you all for yfinance !
import yfinance as yf import sqlite3
def test_crawler(): print(yf.version.version) print(sqlite3.sqlite_version)
y_dict = yf.download(tickers=['7203.T', ], start='2023-01-01', end='2023-02-01',) print(len(y_dict))
def
Hi @clxy,
I ran the following code in Amazon MWAA Airflow:-
import yfinance as yf
import sqlite3
print(yf.version.version)
print(sqlite3.sqlite_version)
y_dict = yf.download(tickers=['7203.T', ], start='2023-01-01', end='2023-02-01',)
print(len(y_dict))
print("Code ran on Amazon Airflow")
This is the output that I got:
[2023-02-07 05:45:41,762] {{logging_mixin.py:104}} INFO - 0.2.9
[2023-02-07 05:45:41,762] {{logging_mixin.py:104}} INFO - 3.7.17
[2023-02-07 05:45:41,773] {{logging_mixin.py:104}} INFO -
[*********************100%***********************] 1 of 1 completed
[2023-02-07 05:45:41,776] {{logging_mixin.py:104}} WARNING - /usr/local/airflow/.local/lib/python3.7/site-packages/watchtower/__init__.py:349 WatchtowerWarning: Received empty message. Empty messages cannot be sent to CloudWatch Logs
[2023-02-07 05:45:41,776] {{logging_mixin.py:104}} WARNING - Traceback (most recent call last):
[2023-02-07 05:45:41,777] {{logging_mixin.py:104}} WARNING - File "/usr/local/airflow/config/cloudwatch_logging.py", line 162, in emit
self.sniff_errors(record)
[2023-02-07 05:45:41,777] {{logging_mixin.py:104}} WARNING - File "/usr/local/airflow/config/cloudwatch_logging.py", line 211, in sniff_errors
if pattern.search(record.message):
[2023-02-07 05:45:41,777] {{logging_mixin.py:104}} WARNING - AttributeError: 'LogRecord' object has no attribute 'message'
[2023-02-07 05:45:41,777] {{logging_mixin.py:104}} INFO -
1 Failed download:
[2023-02-07 05:45:41,777] {{logging_mixin.py:104}} INFO - - 7203.T: OperationalError('near "without": syntax error')
[2023-02-07 05:45:41,777] {{logging_mixin.py:104}} INFO - 0
[2023-02-07 05:45:41,777] {{logging_mixin.py:104}} INFO - Code ran on Amazon Airflow
@clxy If I ran similar code on my local machine
import yfinance as yf
import sqlite3
print(yf.version.version)
print(sqlite3.sqlite_version)
y_dict = yf.download(tickers=['7203.T', ], start='2023-01-01', end='2023-02-01',)
print(len(y_dict))
print("Code ran on local python")
I get the following output:-
0.2.9
3.39.4
[*********************100%***********************] 1 of 1 completed
19
Code ran on local python
@clxy @ValueRaider the issue is that there is no way for me to upgrade the version of the sqlite3 library on Amazon MWAA Airflow.
So effectively, yfinance is broken for me if I use it on Amazon MWAA Airflow.
@jasmohan-narula
I have no idea about Amazon MWAA Airflow. But, as ValueRaider said above
You don't need to. PIP pre-release 0.2.10b1 has a fix for older sqlite verison (and dev branch), can anyone confirm fixed?
And, they just released the 0.2.10 today. So, just re-install yfinance, and try again.