BUG: Connection aborted
awesomekosm opened this issue · comments
Eugene commented
finvizfinance version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the master branch of finvizfinance.
Reproducible Example
run
stock = finvizfinance(ticker)
Issue Description
getting occasional error
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
Expected Behavior
No error or some kind of retry logic.
Installed Versions
'0.14.7'
Tianning Li commented
I cannot reproduce. But can you show me the version of urllib3?
Eugene commented
It's urllib3==2.2.1
All of my dependencies
asgiref==3.7.2
beautifulsoup4==4.12.3
bs4==0.0.2
certifi==2024.2.2
charset-normalizer==3.3.2
DateTime==5.4
Django==5.0.3
djangorestframework==3.14.0
finvizfinance==0.14.7
idna==3.6
lxml==5.1.0
numpy==1.26.4
pandas==2.2.1
python-dateutil==2.9.0.post0
pytz==2024.1
requests==2.31.0
setuptools==69.1.1
six==1.16.0
soupsieve==2.5
sqlparse==0.4.4
tzdata==2024.1
urllib3==2.2.1
zope.interface==6.2
Tianning Li commented
Can you try downgrading urllib3 to 2.0.6? Not sure if this works.
Eugene commented
Will try, thanks for recommendation. Will get back with results.
Eugene commented
It's still happening, I am going to guess it has something to do with my network. If it happens to you and there is a resolution please let me know!
Added a retry
def get_stock_retry(ticker, retry=3):
attempt = 0
while attempt < retry:
try:
# Attempt to fetch stock data
stock = finvizfinance(ticker)
stock_fundament = stock.ticker_fundament()
return stock_fundament
except requests.exceptions.ConnectionError as e:
attempt += 1 # Increment attempt counter if an exception occurs
logger.error(f"Connection error on attempt #{attempt} for {ticker}: {e}")
if attempt == retry: # Log a different message if all retries have been exhausted
logger.error(f"Failed to process {ticker} after {retry} attempts due to connection errors.")