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

Exception near "without": syntax error - ticker.fast_info['market_cap'] #1372

Closed
zacra opened this issue Jan 28, 2023 · 25 comments
Closed

Exception near "without": syntax error - ticker.fast_info['market_cap'] #1372

zacra opened this issue Jan 28, 2023 · 25 comments

Comments

@zacra
Copy link

zacra commented Jan 28, 2023

I want to import 'market_cap' information, but I am getting an error.

Exception near "without": syntax error

check please

@ValueRaider
Copy link
Collaborator

Post exact code that reproduces error.

@zacra
Copy link
Author

zacra commented Jan 28, 2023

ticker = yf.Ticker('AAPL')
print(ticker.fast_info['market_cap'])

@ValueRaider
Copy link
Collaborator

Actually, there's more info you need to provide. Read this properly

@zacra
Copy link
Author

zacra commented Jan 29, 2023

yf version is 0.2.9

OS: AWS amazon Linux 2.0

@ValueRaider
Copy link
Collaborator

ValueRaider commented Jan 29, 2023

  • Error message, with traceback if shown

All exceptions generate a traceback. What is confusing about this request?

@zacra
Copy link
Author

zacra commented Jan 29, 2023

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

@ValueRaider
Copy link
Collaborator

ValueRaider commented Jan 29, 2023

try:
...
except Exception as e:
print("Exception ", e)

You are deliberately discarding the traceback by doing this. Stop making this difficult.

@zacra
Copy link
Author

zacra commented Jan 29, 2023

Oh Sorry..
Error code is

Traceback (most recent call last):
File "/var/autobot/test_i.py", line 20, in
print(stock_info2['market_cap'])
File "/home/ec2-user/.local/lib/python3.7/site-packages/yfinance/base.py", line 110, in getitem
return getattr(self, k)
File "/home/ec2-user/.local/lib/python3.7/site-packages/yfinance/base.py", line 402, in market_cap
shares = self.shares
File "/home/ec2-user/.local/lib/python3.7/site-packages/yfinance/base.py", line 213, in shares
shares = self._tkr.get_shares_full(start=pd.Timestamp.utcnow().date()-pd.Timedelta(days=548))
File "/home/ec2-user/.local/lib/python3.7/site-packages/yfinance/base.py", line 1506, in get_shares_full
tz = self._get_ticker_tz(debug_mode=False, proxy=None, timeout=10)
File "/home/ec2-user/.local/lib/python3.7/site-packages/yfinance/base.py", line 1176, in _get_ticker_tz
cache = utils.get_tz_cache()
File "/home/ec2-user/.local/lib/python3.7/site-packages/yfinance/utils.py", line 839, in get_tz_cache
_tz_cache = _TzCache()
File "/home/ec2-user/.local/lib/python3.7/site-packages/yfinance/utils.py", line 764, in init
self._tz_db = _KVStore(_os.path.join(self._db_dir, "tkr-tz.db"))
File "/home/ec2-user/.local/lib/python3.7/site-packages/yfinance/utils.py", line 721, in init
self.conn.execute('create table if not exists "kv" (key TEXT primary key, value TEXT) without rowid')
sqlite3.OperationalError: near "without": syntax error

@ValueRaider
Copy link
Collaborator

ValueRaider commented Jan 29, 2023

Run this, print output:

import sqlite3
print(sqlite3.sqlite_version)

And what is your Python version?

@zacra
Copy link
Author

zacra commented Jan 29, 2023

Python version is Python 3.7.16
sqlite3 version is 3.7.17

@ValueRaider
Copy link
Collaborator

ValueRaider commented Jan 29, 2023

So that error message generated by old sqlite bundled in old Python. Can update Python to 3.8?

@ValueRaider
Copy link
Collaborator

Alternatively, this branch should fix error: fix/old-sqlite-error. Instructions #1080

@zacra
Copy link
Author

zacra commented Jan 29, 2023

Thanks.

I will try both solutions!

@zacra
Copy link
Author

zacra commented Jan 29, 2023

I solved it by upgrading the sqlite3 version.
thank you!

@rpandit-info
Copy link

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?

@jasmohan-narula
Copy link

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

@zacra
Copy link
Author

zacra commented Feb 2, 2023

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

@jasmohan-narula
Copy link

@zacra Locally I'm able to update sqlite.
Not sure how I will be able to update on AWS Airflow.

@zacra
Copy link
Author

zacra commented Feb 2, 2023

@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

@ValueRaider
Copy link
Collaborator

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?

@clxy
Copy link

clxy commented Feb 4, 2023

@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 !

@jasmohan-narula
Copy link

jasmohan-narula commented Feb 7, 2023

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

@jasmohan-narula
Copy link

@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

@jasmohan-narula
Copy link

jasmohan-narula commented Feb 7, 2023

@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.

@clxy
Copy link

clxy commented Feb 8, 2023

@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.

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

5 participants