Repository: ranaroussi/yfinance

Issue:
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


Discussion:
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](https://github.com/ranaroussi/yfinance/issues/new?assignees=&labels=&template=bug_report.md&title=)
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 <module>
    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


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?

Resolving patch:
diff --git a/yfinance/utils.py b/yfinance/utils.py
--- a/yfinance/utils.py
+++ b/yfinance/utils.py
@@ -723,7 +723,14 @@ def __init__(self, filename):
         with self._cache_mutex:
             self.conn = _sqlite3.connect(filename, timeout=10, check_same_thread=False)
             self.conn.execute('pragma journal_mode=wal')
-            self.conn.execute('create table if not exists "kv" (key TEXT primary key, value TEXT) without rowid')
+            try:
+                self.conn.execute('create table if not exists "kv" (key TEXT primary key, value TEXT) without rowid')
+            except Exception as e:
+                if 'near "without": syntax error' in str(e):
+                    # "without rowid" requires sqlite 3.8.2. Older versions will raise exception
+                    self.conn.execute('create table if not exists "kv" (key TEXT primary key, value TEXT)')
+                else:
+                    raise
             self.conn.commit()
         _atexit.register(self.close)
 


Test patch: