alvarobartt / investpy

Financial Data Extraction from Investing.com with Python
https://investpy.readthedocs.io/
MIT License
1.59k stars 374 forks source link

403 when getting historical data #591

Open kartickvad opened 1 year ago

kartickvad commented 1 year ago

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.

ymyke commented 1 year ago

Your command should work. Did you try again (much) later?

kartickvad commented 1 year ago

I tried now, and it again didn't work.

ymyke commented 1 year ago

Strange. It works when I run it.

Maybe you're blocked for good by investing.com for some reason? Did you access the site excessively?

You could try to change your IP address w a VPN software.

kartickvad commented 1 year ago

Thanks for helping. I tried tethering via my phone, and the same problem occurs.

ymyke commented 1 year ago

Very odd – your code works as expected in my environment.

ymyke commented 1 year ago

Can you access investing.com from a browser and lookup AAPL?

kartickvad commented 1 year ago

Works. image

ymyke commented 1 year ago

Then I can't think of anything else I'm afraid.

filipegarcia commented 1 year ago

getting the same error on currency crosses

  File "/usr/local/lib/python3.8/site-packages/investpy/currency_crosses.py", line 550, in get_currency_cross_historical_data
    raise ConnectionError("ERR#0015: error " + str(req.status_code) + ", try again later.")
ConnectionError: ERR#0015: error 429, try again later.

investing.com is behind cloudflare and blocked

# curl https://www.investing.com/ -I
HTTP/2 403
date: Thu, 08 Sep 2022 12:58:54 GMT
content-type: text/html; charset=iso-8859-1
cf-cache-status: DYNAMIC
set-cookie: __cf_bm=wnVdhEwHEhO8B0gM_G2XxuabRlLCuU8PgcZxy6Mg_b0-1662641934-0-AVVmD7joMZBfCVLchivywtSExeTmZanXwG9d+HxKR2eEOyMeXn47lAUBSIO2uAMq8x1kenX2T3D/Z+pZidfdg/c=; path=/; expires=Thu, 08-Sep-22 13:28:54 GMT; domain=.investing.com; HttpOnly; Secure; SameSite=None
set-cookie: __cflb=02DiuGRugds2TUWHMkimMbdK71gXQtrnibUBnDVsYFNtc; SameSite=None; Secure; path=/; expires=Fri, 09-Sep-22 11:58:54 GMT; HttpOnly
server: cloudflare
cf-ray: 7477dbb98fa19211-FRA
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
younggotti commented 1 year ago

Same here. This stopped working today: ibex = investpy.get_index_historical_data(index='IBEX Total Return', country='spain', from_date='01/01/2020', to_date='01/01/2021') I also tried changing my ip but it didn't work...

Exganza commented 1 year ago

Same here, Stopped working today ->

tasi = investpy.indices.get_index_historical_data('Tadawul All Share', country='Saudi Arabia', from_date='01/01/2019', to_date=today, as_json=False, interval='Daily')

mobinzk commented 1 year ago

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

rgerbranda commented 1 year ago

Same issue here, investpy stopped working yesterday, error 403

search_result = investpy.search_quotes(text='BE0026549684', countries=['belgium'], n_results=1)

recent_data = search_result.retrieve_recent_data()
alvarobartt commented 1 year ago

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 :smile:

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

hscho77 commented 1 year ago

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"?

webdevzilla commented 1 year ago

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!

owinoalfred commented 9 months ago

frustrated!