benjamincham / freeoptionschain

Free Options Chain
MIT License
22 stars 3 forks source link

NameError: name 'HTMLSession' is not defined #16

Open danielhaviv opened 8 hours ago

danielhaviv commented 8 hours ago

Trying to run through the example in the Readme raises:

(options) daniel.haviv@W6NGC7J67V options % python test.py Traceback (most recent call last): File "/Users/daniel.haviv/Documents/Projects/options/test.py", line 6, in options_chain = ref_FOC.get_expiration_dates("AAPL") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/daniel.haviv/Documents/Projects/options/lib/python3.12/site-packages/FOC/main.py", line 43, in get_expiration_dates expiration_dates = op.get_expiration_dates(ticker) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/daniel.haviv/Documents/Projects/options/lib/python3.12/site-packages/yahoo_fin/options.py", line 101, in get_expiration_dates session = HTMLSession() ^^^^^^^^^^^ NameError: name 'HTMLSession' is not defined

Steps to reproduce:

  1. python3 -m venv options
  2. pip install freeoptionschain
  3. run the following code:
    
    #create instance
    ref_FOC = FOC()

Fetch options expiration dates for 'AAPL'

options_chain = ref_FOC.get_expiration_dates("AAPL")`

danielhaviv commented 8 hours ago

removing the exception block from the imports (so just importing HTMLSession) raises the following exception:

Traceback (most recent call last): File "/Users/daniel.haviv/Documents/Projects/options/test.py", line 1, in from FOC import FOC File "/Users/daniel.haviv/Documents/Projects/options/lib/python3.12/site-packages/FOC/init.py", line 5, in from .main import FOC File "/Users/daniel.haviv/Documents/Projects/options/lib/python3.12/site-packages/FOC/main.py", line 8, in from yahoo_fin import options as op File "/Users/daniel.haviv/Documents/Projects/options/lib/python3.12/site-packages/yahoo_fin/options.py", line 7, in from requests_html import HTMLSession File "/Users/daniel.haviv/Documents/Projects/options/lib/python3.12/site-packages/requests_html.py", line 14, in from lxml.html.clean import Cleaner File "/Users/daniel.haviv/Documents/Projects/options/lib/python3.12/site-packages/lxml/html/clean.py", line 18, in raise ImportError( ImportError: lxml.html.clean module is now a separate project lxml_html_clean. Install lxml[html_clean] or lxml_html_clean directly.

danielhaviv commented 8 hours ago

Installing lxml_html_clean raises the following exception:

File "/Users/daniel.haviv/Documents/Projects/options/test.py", line 6, in options_chain = ref_FOC.get_expiration_dates("AAPL") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/daniel.haviv/Documents/Projects/options/lib/python3.12/site-packages/FOC/main.py", line 45, in get_expiration_dates expiration_dates[idx] = datetime.strptime(expiration_date, "%B %d, %Y").strftime("%Y-%m-%d") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/_strptime.py", line 554, in _strptime_datetime tt, fraction, gmtoff_fraction = _strptime(data_string, format) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/_strptime.py", line 333, in _strptime raise ValueError("time data %r does not match format %r" % ValueError: time data '\n' does not match format '%B %d, %Y'