Repository: ranaroussi/yfinance

Issue:
peewee.OperationalError: near "WITHOUT": syntax error
### Describe bug

When trying to access the .info property of the Ticker object, I am getting the following error.

### Simple code that reproduces your problem

yf_ticker = yf.Ticker(ticker)
info = yf_ticker.info

### Debug log

 info = yf_ticker.info
           ^^^^^^^^^^^^^^
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/ticker.py", line 154, in info
    return self.get_info()
           ^^^^^^^^^^^^^^^
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/base.py", line 1779, in get_info
    data = self._quote.info
           ^^^^^^^^^^^^^^^^
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/scrapers/quote.py", line 574, in info
    self._fetch_info(self.proxy)
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/scrapers/quote.py", line 649, in _fetch_info
    result = self._fetch(proxy, modules=modules)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/scrapers/quote.py", line 638, in _fetch
    result = self._data.get_raw_json(_QUOTE_SUMMARY_URL_ + f"/{self._symbol}", user_agent_headers=self._data.user_agent_headers, params=params_dict, proxy=proxy)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/data.py", line 399, in get_raw_json
    response = self.get(url, user_agent_headers=user_agent_headers, params=params, proxy=proxy, timeout=timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/utils.py", line 103, in wrapper
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/data.py", line 348, in get
    cookie, crumb, strategy = self._get_cookie_and_crumb()
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/utils.py", line 103, in wrapper
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/data.py", line 324, in _get_cookie_and_crumb
    cookie, crumb = self._get_cookie_and_crumb_basic(proxy, timeout)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/utils.py", line 103, in wrapper
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/data.py", line 213, in _get_cookie_and_crumb_basic
    cookie = self._get_cookie_basic(proxy, timeout)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/data.py", line 156, in _get_cookie_basic
    self._cookie = self._load_cookie_basic()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/data.py", line 142, in _load_cookie_basic
    cookie_dict = cache.get_cookie_cache().lookup('basic')
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/cache.py", line 355, in lookup
    self.initialise()
  File "/home/ec2-user/.local/lib/python3.11/site-packages/yfinance/cache.py", line 347, in initialise
    db.create_tables([_CookieSchema])
  File "/home/ec2-user/.local/lib/python3.11/site-packages/peewee.py", line 3441, in create_tables
    model.create_table(**options)
  File "/home/ec2-user/.local/lib/python3.11/site-packages/peewee.py", line 6948, in create_table
    cls._schema.create_all(safe, **options)
  File "/home/ec2-user/.local/lib/python3.11/site-packages/peewee.py", line 6050, in create_all
    self.create_table(safe, **table_options)
  File "/home/ec2-user/.local/lib/python3.11/site-packages/peewee.py", line 5901, in create_table
    self.database.execute(self._create_table(safe=safe, **options))
  File "/home/ec2-user/.local/lib/python3.11/site-packages/peewee.py", line 3260, in execute
    return self.execute_sql(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/.local/lib/python3.11/site-packages/peewee.py", line 3250, in execute_sql
    with __exception_wrapper__:
  File "/home/ec2-user/.local/lib/python3.11/site-packages/peewee.py", line 3020, in __exit__
    reraise(new_type, new_type(exc_value, *exc_args), traceback)
  File "/home/ec2-user/.local/lib/python3.11/site-packages/peewee.py", line 192, in reraise
    raise value.with_traceback(tb)
  File "/home/ec2-user/.local/lib/python3.11/site-packages/peewee.py", line 3252, in execute_sql
    cursor.execute(sql, params or ())
peewee.OperationalError: near "WITHOUT": syntax error

### Bad data proof

_No response_

### `yfinance` version

0.2.35

### Python version

3.11

### Operating system

linux (amazon ec2)


Discussion:
I tried troubleshooting from a similar looking issue here: https://github.com/ranaroussi/yfinance/issues/1372

But there is no matching distribution of sqlite3 on python3.11 that pip could resolve to.

The funny thing is the same code with all the same packages running on my Mac works just fine. Something specific to running in the linux env is related. Could this issue be similar to https://github.com/ranaroussi/yfinance/issues/1821
What is version of sqlite? At minimum there should be a version bundled in Python.
Interestingly, I could not find a version of sqlite or sqlite3. On my local too where this issue does not happen, neither of these packages are installed either.

$ pip show sqlite
WARNING: Package(s) not found: sqlite
$ pip show sqlite3
WARNING: Package(s) not found: sqlite3

I will try the caching path suggestion you recommended in this post to start with: https://github.com/ranaroussi/yfinance/issues/1821
Bundled in Python means ignore PIP. Just do `import sqlite ; sqlite.__version__`

#1821 is a different problem.
I see, thank you for that clarification! In my python3.11, I only was able to import sqlite3, and the version is 2.6.0 `import sqlite3 ; sqlite3.version`. In my local env, the sqlite3 version is the same as on the VM.

Resolving patch:
diff --git a/yfinance/cache.py b/yfinance/cache.py
--- a/yfinance/cache.py
+++ b/yfinance/cache.py
@@ -145,7 +145,14 @@ def initialise(self):
 
         db.connect()
         tz_db_proxy.initialize(db)
-        db.create_tables([_KV])
+        try:
+            db.create_tables([_KV])
+        except _peewee.OperationalError as e:
+            if 'WITHOUT' in str(e):
+                _KV._meta.without_rowid = False
+                db.create_tables([_KV])
+            else:
+                raise
         self.initialised = 1  # success
 
     def lookup(self, key):
@@ -344,7 +351,14 @@ def initialise(self):
 
         db.connect()
         Cookie_db_proxy.initialize(db)
-        db.create_tables([_CookieSchema])
+        try:
+            db.create_tables([_CookieSchema])
+        except _peewee.OperationalError as e:
+            if 'WITHOUT' in str(e):
+                _CookieSchema._meta.without_rowid = False
+                db.create_tables([_CookieSchema])
+            else:
+                raise
         self.initialised = 1  # success
 
     def lookup(self, strategy):


Test patch: