investpy: 403 when getting historical data

Thanks for building and running this project.

I’m trying to run the sample code from https://pypi.org/project/investpy/:

import investpy

df = investpy.get_stock_historical_data(stock='AAPL',
                                        country='United States',
                                        from_date='01/01/2010',
                                        to_date='01/01/2020')
print(df.head())

and I’m getting a 403:


Traceback (most recent call last):
  File ["Untitled.py", line 5](coderunner://Untitled.py#5:0!), in <module>
    df = investpy.get_stock_historical_data(stock='AAPL',
  File ["/Users/kartick/Library/Python/3.8/lib/python/site-packages/investpy/stocks.py", line 664](coderunner:///Users/kartick/Library/Python/3.8/lib/python/site-packages/investpy/stocks.py#664:0!), in get_stock_historical_data
    raise ConnectionError(
ConnectionError: ERR#0015: error 403, try again later.

I tried five times over 12 hours, so it’s not transient.

Is there another way to make it work? Apologies if it’s a mistake on my side.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

Hi everyone, please check https://github.com/alvarobartt/investpy/issues/600, I’m currently fixing it, the patch shouldn’t take too long! Hopefully by the end of the day 😄

I’ll post more information at https://twitter.com/alvarobartt/status/1570661023262310402

File “D:\Anaconda3\lib\site-packages\investpy\currency_crosses.py”, line 674, in get_currency_cross_historical_data raise ConnectionError( ConnectionError: ERR#0015: error 403, try again later.

Hi, alvarobartt

When will you fix “get_currency_cross_historical_data”?

frustrated!

Hello everyone!

As a temporary (or permanent) solution, I have built an API that will bypass Cloudflare.

Using it is as simple as prefixing your current GET requests with this: http://api.scraperlink.com/investpy/?email=your@email.com&url=

Example:

http://api.scraperlink.com/investpy/?email=your@email.com&url=https%3A%2F%2Fapi.investing.com%2Fapi%2Ffinancialdata%2Fhistorical%2F7%3Fstart-date%3D2022-09-29%26end-date%3D2022-09-29%26time-frame%3DDaily%26add-missing-rows%3Dfalse

Please be sure to replace “email” with your actual one if you want to receive updates. I want to be able to alert everyone if something breaks. It doesn’t verify email addresses, so if you don’t care for that, you can plug any email address.

It also supports historical data for stocks, cryptos and currencies. You can learn more here: https://api.scraperlink.com/investpy

If you guys need more functionality or data points added, just let me know.

Hope this helps!

I’ve the same issue, from my investigation https://www.investing.com/instruments/HistoricalDataAjax seems to be discontinued!