Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

403 when getting historical data #591

Open
kartickvad opened this issue Jul 31, 2022 · 17 comments · May be fixed by #602
Open

403 when getting historical data #591

kartickvad opened this issue Jul 31, 2022 · 17 comments · May be fixed by #602

Comments

@kartickvad
Copy link

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
Copy link
Contributor

ymyke commented Aug 2, 2022

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

@kartickvad
Copy link
Author

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

@ymyke
Copy link
Contributor

ymyke commented Aug 2, 2022

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
Copy link
Author

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

@ymyke
Copy link
Contributor

ymyke commented Aug 2, 2022

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

@ymyke
Copy link
Contributor

ymyke commented Aug 2, 2022

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

@kartickvad
Copy link
Author

Works.
image

@ymyke
Copy link
Contributor

ymyke commented Aug 3, 2022

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

@filipegarcia
Copy link

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
Copy link

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
Copy link

Exganza commented Sep 15, 2022

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
Copy link

mobinzk commented Sep 15, 2022

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

@rgerbranda
Copy link

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
Copy link
Owner

Hi everyone, please check #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

@hscho77
Copy link

hscho77 commented Sep 19, 2022

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
Copy link

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
Copy link

frustrated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.