Open danielhaviv opened 1 month 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.
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'
Got the Same error
ValueError: time data '\n' does not match format '%B %d, %Y'
First step to fix this is using updated yahoo_fin:
pip install yahoo_fin_cheese
https://github.com/atreadw1492/yahoo_fin/pull/121
2.
--- a/FOC/main.py
+++ b/FOC/main.py
def get_expiration_dates(self,ticker):
expiration_dates = op.get_expiration_dates(ticker)
for idx, expiration_date in enumerate(expiration_dates):
- expiration_dates[idx] = datetime.strptime(expiration_date, "%B %d, %Y").strftime("%Y-%m-%d")
+ expiration_dates[idx] = datetime.strptime(expiration_date, "%b %d, %Y").strftime("%Y-%m-%d")
return expiration_dates
But now I get:
[..]
File "/freeoptionschain/FOC/main.py", line 119, in json_extract_node
raise ValueError("Invalid json keys."
The response from the nasdaq API is:
{'data': None, 'message': None, 'status': {'rCode': 400, 'bCodeMessage': [{'code': 1001, 'errorMessage': 'Symbol not exists.'}], 'developerMessage': None}}
Trying to run through the example in the Readme raises:
Steps to reproduce:
Fetch options expiration dates for 'AAPL'
options_chain = ref_FOC.get_expiration_dates("AAPL")`