Forums

ValueError: read of closed file

I am trying to access yahoo finance from a web app and I am getting this ValueError. I see that yahoo.com is whitelisted on my free account. Do I need to add a special call somewhere in one of my source files if I am trying to call an external site? This program works fine when I run it from my local computer, address is : stock.pythonanywhere.com/status/ and the error pops up when I hit the update quote button. Thanks for any pointers you might have!

What does the update do? ie. what is the call to access yahoo.com?

The update button from the html calls a function that pulls data using the YahooFinancials app, https://pypi.org/project/yahoofinancials/

the code is like this:

from yahoofinancials import YahooFinancials as yf

def update_quote(self, symbol):
        pull_data = yf(symbol)
        sym = pull_data.get_stock_price_data(reformat=True)
        current_price = sym[symbol]['regularMarketPrice']
        return current_price

This code works when I run it standalone and also within my django app when I run it on the local server. The problem I am getting is when I run it uploaded to the pythonanywhere site.

Where are you seeing the error message? Is it in the error log? If so, could you post the full traceback?