investpy: ConnectionError: ERR#0015: error 403, try again later.

Code-

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())

Error-

ConnectionError                           Traceback (most recent call last)
[<ipython-input-4-f6f4235b7e47>](https://localhost:8080/#) in <module>
      4                                         country='United States',
      5                                         from_date='01/01/2010',
----> 6                                         to_date='01/01/2020')
      7 print(df.head())

[/usr/local/lib/python3.7/dist-packages/investpy/stocks.py](https://localhost:8080/#) in get_stock_historical_data(stock, country, from_date, to_date, as_json, order, interval)
    663         if req.status_code != 200:
    664             raise ConnectionError(
--> 665                 "ERR#0015: error " + str(req.status_code) + ", try again later."
    666             )
    667 

ConnectionError: ERR#0015: error 403, try again later.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 7
  • Comments: 106 (27 by maintainers)

Commits related to this issue

Most upvoted comments

Hi everyone! Iā€™ve checked this issue and it seems that the internal API that Investing.com uses has changed without prior notice, as this is not an official implementation. Sorry for the inconvenience, this issue will be solved in the upcoming days, hopefully, today Iā€™ll push a patch to solve this, Iā€™ll share later on with you the branch where Iā€™m working actively to solve this!

So Iā€™ve already contacted Investing.com and started a conversation there, Iā€™ll let you all know the outcome of it. Thanks for your patience! šŸ¤—

Both get_stock_recent_data and get_stock_historical_data are fixed in https://github.com/alvarobartt/investpy/tree/403-patch, Iā€™ll add the comments of the fix in an upcoming PR! In the meantime, you can install the latest investpy version from 403-patch branch as pip install git+https://github.com/alvarobartt/investpy@403-patch

Soooo it seems that it was working like 1 hour away or so and now suddenly stopped working againā€¦ So Iā€™ll keep on investigating itā€¦ It works from the browser and also from Postman, Thunder Client, and similar, but from Python it seems that it doesnā€™t work nowā€¦

Hi guys, Iā€™m having the same problem, does anyone have any tips to get around this situation?

dados_usd_brl = investpy.currency_crosses.get_currency_cross_historical_data(currency_cross=ā€˜USD/BRLā€™, from_date=ā€˜04/11/2019ā€™, to_date= ā€˜01/01/2024ā€™)

Hi @Exganza so the fix is pending, since stocks stopped working too in the 403-patch branch for no reason (already using the new Investing.com API), so I got to fix it but then stopped working, Iā€™m actively checking it! Iā€™ll let you all know whenever I have more updates, sorry for the inconvenience!

Hello everyone!

I was using a custom script for investing.com, which led me to investpy when things broke.

I ended up building a solution, but feel guilty not sharing it with everyone stuck on this issue. So, here is the API to bypass Cloudflare: http://api.scraperlink.com/investpy/

Using it in your scripts is just a matter of prefixing your current fetch 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

I have also added another option that supports historical data for stocks, cryptos and currencies for now:

Basics:
* email= So we can send important updates
* type= historical_data
* products=cryptos,currency_crosses,stocks
* from_date=Y-m-d
* to_date= Y-m-d
- time_frame=Daily,Monthly,Weekly

stocks:
* country=
* id=, symbol= or name=
Example: http://api.scraperlink.com/investpy/?email=your@email.com&type=historical_data&product=stocks&country=united%20states&symbol=TSLA&from_date=09/27/2022&to_date=09/28/2022

cryptos:
* id=, symbol= or name=
Example: http://api.scraperlink.com/investpy/?email=your@email.com&type=historical_data&product=cryptos&symbol=BTC&from_date=09/27/2022&to_date=09/28/2022

currency_crosses:
* id= or name=
Example: http://api.scraperlink.com/investpy/?email=your@email.com&type=historical_data&product=currency_crosses&name=USD/CAD&from_date=09/27/2022&to_date=09/28/2022

If thereā€™s interest from the community, I am happy to add more features and data points.

Just let me know whatā€™s important to you.

Hi everyone! Good news šŸŽ‰

Iā€™ve just released investiny which is a tiny investpy with a single function to download the historical data from Investing.com, check it out at https://github.com/alvarobartt/investiny (support is welcomed so if itā€™s useful to you in the meantime while investpy is fixed please star it and share it so that anyone can use it while we fix investpy)

Thanks to everyone contributing and helping out! šŸ¤—

I guess that one possible solution is using origin server ip adress of ā€˜api.investing.comā€™ instead of cloudflare ip address.

reference https://www.youtube.com/watch?v=Cfbi5-Knpxk https://blog.detectify.com/2019/07/31/bypassing-cloudflare-waf-with-the-origin-server-ip-address/

But, I canā€™t found origin server ip address of ā€˜api.investing.comā€™. ( ā€˜CloudFailā€™ canā€™t find it. )

Can anyone do it?

You can use [investiny] I do have the same error message using it. In fine, anyone has a reliable alternative as it can be serious to build a download script given this restriction. Anyone got answer from investing; com ?

You can use the workaround API that I built for this community: http://api.scraperlink.com/investpy/

For example, hereā€™s the sample API for stocks:

http://api.scraperlink.com/investpy/?email=your@email.com&type=historical_data&product=stocks&country=united states&symbol=TSLA&from_date=09/27/2022&to_date=09/28/2022

Thanks, @samjmck this is really useful, thereā€™s a limitation on the daily period itā€™s retrieved 365 days maximum, but still very useful

Commodity historical data not working

investpy.get_commodity_historical_data

ConnectionError: ERR#0015: error 403, try again later.

hi, still having issues.

import investiny from investiny import historical_data data = historical_data(investing_id=6408, from_date=ā€œ09/01/2022ā€, to_date=ā€œ10/01/2022ā€)

i get ā€œConnectionError: Request to Investing.com API failed with error code: 403.ā€**

Hi, @alvarobartt !

Iā€™ve encountered the 403 Error problem today and found that using curl seem to be working fine, no 403 error.

And the only difference I can see is the headers ordering - requests shuffles headers, while curl preserves them as provided.

So I tried using urllib.request and it worked.

Iā€™m using Python 3.10.5

Maybe this can solve all 403 errors in the project?

minimal working example:


import urllib.request



# take them from your browser, no cookies required

headers = {}



req = urllib.request.Request(f'https://sbcharts.investing.com/events_charts/us/222.json', b"", headers)

with urllib.request.urlopen(req) as response:

    response = response.read().decode()

Thanks @KostyaCholak can you please open a separate issue at https://github.com/alvarobartt/investiny? Iā€™ll try to test that approach later today, thanks!

Are you sure that the workaround via https://tvc4.investing.com/ doesnā€™t violate their TOS, @alvarobartt ?

Hi @ymyke so we are mentioning the source the data comes from and itā€™s a publicly available API. What may violate those is to actually bypass their protection protocols, but not sure, this is why Iā€™m telling people developing their own solutions to contact Investing.com just like I did some time ago, to get their approval.

FYI Iā€™ve created here an issue at https://github.com/alvarobartt/investpy/issues/611, and a Discussing at https://github.com/alvarobartt/investpy/discussions/612, both are pinned and have some details on how to use investiny which is a tiny version of investpy that Iā€™ve just created so as to develop there some temporary solutions to keep on pulling data from Investing.com, without having to bypass their protection or violate their terms of use.

Hi everyone! Good news šŸŽ‰

Iā€™ve just released investiny which is a tiny investpy with a single function to download the historical data from Investing.com, check it out at https://github.com/alvarobartt/investiny (support is welcomed so if itā€™s useful to you in the meantime while investpy is fixed please star it and share it so that anyone can use it while we fix investpy)

Thanks to everyone contributing and helping out! šŸ¤—

How do we get the investing_id? running search quotes on investor gives the same 403 error

It seems that after a certain number of requests Cloudflare blocks youā€¦ So itā€™s not stableā€¦

You can use [investiny] I do have the same error message using it. In fine, anyone has a reliable alternative as it can be serious to build a download script given this restriction. Anyone got answer from investing; com ?

You can use the workaround API that I built for this community: http://api.scraperlink.com/investpy/ For example, hereā€™s the sample API for stocks:

http://api.scraperlink.com/investpy/?email=your@email.com&type=historical_data&product=stocks&country=united states&symbol=TSLA&from_date=09/27/2022&to_date=09/28/2022

Thanks a lot for this šŸ˜ƒ

However, after using few times, I get below error msg.

Error message : Expecting value: line 1 column 1 (char 0)

I donā€™t think that error is from me. Whatā€™s the query youā€™re using?

Hi KTHor2,

Thanks for your reply. So Investpy is currently not working due to this error, and there is no solution for this? What do you mean when you say the ā€œcurrent API is protectedā€?

You can use investiny in the meantime, even though at some point youā€™ll face the same issue with Investing.com temporarily blocking you if you send too many requestsā€¦ Iā€™ve already contacted Investing.com in order to look for a solution to thisā€¦ Iā€™ll keep you all posted regarding this matter!

hello everyone, my name is andres, I am a python programming student and investPY made me very happy, I would like to know if maybe investPY could find a solution by the end of the year? I donā€™t know how serious the error is but from what Iā€™ve been investigating it seems to be an update issue of investing.com itself. I thank all developers for their time and stay tuned.

Hi, @AyseTheArk do you mind opening that as a separate issue at https://github.com/alvarobartt/investiny/issues? Otherwise is just a mess for me to go through all the issues here, thanks!

Hi everyone! Good news šŸŽ‰ Iā€™ve just released investiny which is a tiny investpy with a single function to download the historical data from Investing.com, check it out at https://github.com/alvarobartt/investiny (support is welcomed so if itā€™s useful to you in the meantime while investpy is fixed please star it and share it so that anyone can use it while we fix investpy) Thanks to everyone contributing and helping out! šŸ¤—

How do we get the investing_id? running search quotes on investor gives the same 403 error

To get the investing_id:

1. Navigate to https://tvc4.investing.com/

2. Open your browser console, go to network tab

3. Use the investing.com search bar to find your stock and click it

4. Search the network tab for the `/history?symbol=` and the `symbol` query param is your `investing_id`

Hi @fredericojordan, so this works if doing it manually, but Iā€™m planning to actually develop a way to automatically retrieve those in order to avoid either manual search or relying on static CSV files!

Please star investiny and create all the related issues there, not here, as itā€™s easier for me to track, thanks! šŸ¤—

For anyone looking to temporarily switch to yahoo for prices, market-prices offers an interface with enhanced querying and additional functionality.

I was hoping to add investpy as a data source for market-prices although was waiting for intraday data to be added (I know there had been intermittent chatter about this). If investpy can get back up and running (šŸ¤žšŸ¤ž) then Iā€™ll look to add it as a option for the source data.

Good luck @alvarobartt!

EDIT: for anyone looking at market-prices, the pandas dependency is temporarily <= 1.4.4 (working on a fix for the recent 1.5 release - https://github.com/maread99/market_prices/issues/89).

BTW & FWIW: I updated the tessa package (https://github.com/ymyke/tessa) to use yfinance instead of investpy. (Thereā€™s all kinds of other improvements as well.) yfinance is of course not the optimal replacement for investpy but better than nothing for many use cases. ā€“ Still hoping for a resolution here and will re-add investpy once it becomes available again.

So to everyone looking for an alternative as @ymyke is mentioning you can use finance from @ranaroussi, or even his own custom package tessa which is currently using yfinance in the background.

It might be worth using a MITM proxy on an Android or iOS device to check the requests the mobile app is making to the server. Those might be different to the web app and might not have the same protections.

Hi guys, so thereā€™s not much progress from my side, as it seems that the Cloudflare protection cannot be ignored, so the patch just works for a limited number of requestsā€¦ But ends up failing every time!

In my case, itā€™s useful, for instance:

ident = <path>+ā€œstocks.xlsxā€ read_tag = pd.read_excel(ident) ā€¦ tag2 = read_tag[read_tag[ā€˜countryā€™] == ā€˜united statesā€™] tag3 = tag2.loc[tag2[ā€˜symbolā€™] == ā€˜TSLAā€™, ā€˜tagā€™] tag = tag3.values[0]

ex: https://www.investing.com/equities/tesla-motors-ratios

url = ā€˜https://www.investing.com/equities/ā€˜+tag+ā€™-ratiosā€™ driver.get(url)

get Price to Cash Flow

find_rating = driver.find_element(By.XPATH, ā€œ(//tr[@id=ā€˜childTrā€™]/td/div/table/tbody/tr[3]/td[2])ā€) p_cf = find_rating.text

its all available in the investpy resources folder -> Lib\site-packages\investpy\resources ID col in stocks.csv

Iā€™m a newbie so Iā€™m probably missing something but scraping from the following url seems to work still fine (I donā€™t know how long it will last) https://advcharts.investing.com/advinion2016/advanced-charts/9/9/16/GetRecentHistory?strSymbol=46891&iTop=1500&strPriceType=bid&strFieldsMode=allFields&lang_ID=9&strTimeFrame=1D

Hi again everyone, feel free to track the progress of the patch at https://github.com/alvarobartt/investpy/pull/602 šŸ¤— Iā€™d also appreciate some feedback from the ones testing it! So drop your feedback either here or in https://twitter.com/alvarobartt/status/1570661023262310402

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