investpy icon indicating copy to clipboard operation
investpy copied to clipboard

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

Open divyankm opened this issue 2 years ago • 106 comments

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.

divyankm avatar Sep 15 '22 16:09 divyankm

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

mobinzk avatar Sep 15 '22 17:09 mobinzk

I've the same issue.

PatiPimenta avatar Sep 15 '22 17:09 PatiPimenta

Same issue, any update on this?

campernate avatar Sep 15 '22 20:09 campernate

I have the same accion = 'AAPL' search_result = investpy.search_quotes(text=accion, products=['stocks'], countries=['united states'], n_results=1)

File "D:\Python39\lib\site-packages\investpy\search.py", line 127, in search_quotes raise ConnectionError(f"ERR#0015: error {req.status_code}, try again later.") ConnectionError: ERR#0015: error 403, try again later.

Sebara0 avatar Sep 16 '22 00:09 Sebara0

Same here.

/usr/local/lib/python3.7/dist-packages/investpy/stocks.py 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.

lstavares84 avatar Sep 16 '22 01:09 lstavares84

Same here. Did some research and it seems error 403 indicates that the server understands the request but refuses to authorize it.

cypresswang avatar Sep 16 '22 01:09 cypresswang

You can still pull the economic calendar but everything else seems to be returning a 403.

nicklatin avatar Sep 16 '22 02:09 nicklatin

Also confirming get_index_historical_data yields "ConnectionError: ERR#0015: error 403, try again later" (tried multiple US symbols) but econ calendar still works. Was working yesterday

drnarc avatar Sep 16 '22 02:09 drnarc

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!

alvarobartt avatar Sep 16 '22 06:09 alvarobartt

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

alvarobartt avatar Sep 16 '22 09:09 alvarobartt

Hi again everyone, feel free to track the progress of the patch at https://github.com/alvarobartt/investpy/pull/602 :hugs: 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

alvarobartt avatar Sep 16 '22 09:09 alvarobartt

Commodity historical data not working

investpy.get_commodity_historical_data

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

Development-Platforms avatar Sep 16 '22 09:09 Development-Platforms

Hi @alvarobartt , get_historcal_data is working. get_index_historical_data is not working. `` Code-

df = investpy.get_index_historical_data(index="S&P 500",country="United States",from_date="01/01/2010",to_date="01/01/2022")
df

Error-

---------------------------------------------------------------------------
ConnectionError                           Traceback (most recent call last)
[<ipython-input-31-5e1d4758da05>](https://localhost:8080/#) in <module>
----> 1 df = investpy.get_index_historical_data(index="S&P 500",country="United States",from_date="01/01/2010",to_date="01/01/2022")
      2 df

[/usr/local/lib/python3.7/dist-packages/investpy/indices.py](https://localhost:8080/#) in get_index_historical_data(index, country, from_date, to_date, as_json, order, interval)
    648         if req.status_code != 200:
    649             raise ConnectionError(
--> 650                 "ERR#0015: error " + str(req.status_code) + ", try again later."
    651             )
    652 

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

Really Appreciate your efforts. Thank you so much.

divyankm avatar Sep 16 '22 09:09 divyankm

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

Could anyone help me on how to install the patch? Python gives me an error. Thank you!

MetalComm avatar Sep 16 '22 09:09 MetalComm

Could anyone help me on how to install the patch? Python gives me an error. Thank you!

@MetalComm Which IDE you are using, For Colab IDE Use >> !pip install git+https://github.com/alvarobartt/investpy@403-patch For other IDE, check with the pip version or try using pip3 for python version 3+

divyankm avatar Sep 16 '22 09:09 divyankm

pip3

thank you, but... is the URL correct? Beacause I get this error: Could not install requirement https://github.com/alvarobartt/investpy@403-patch because of HTTP error 404 Client Error: Not Found for url: https://github.com/alvarobartt/investpy@403-patch for URL https://github.com/alvarobartt/investpy@403-patch

MetalComm avatar Sep 16 '22 10:09 MetalComm

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

Did installed the patch and tried to run my programs, but still getting the same ConnectionError: ERR#0015: error 403, try again later.

BTW, I'm using the below:

investpy.get_index_historical_data()
investpy.search_quotes()
investpy.get_stock_recent_data()

srinivasakumar-a avatar Sep 16 '22 11:09 srinivasakumar-a

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...

alvarobartt avatar Sep 16 '22 11:09 alvarobartt

indices method still not work

df = investpy.indices.get_index_historical_data

Exganza avatar Sep 16 '22 12:09 Exganza

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!

alvarobartt avatar Sep 16 '22 12:09 alvarobartt

It seems that after a certain number of requests Cloudflare blocks you... So it's not stable...

alvarobartt avatar Sep 16 '22 13:09 alvarobartt

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!

thank you @alvarobartt

Exganza avatar Sep 16 '22 13:09 Exganza

I found incomplete solution using cloudscraper module. ( NOTE!, incomplete solution ) This module bypass cloudeflare.

  1. [OK] https://www.investing.com
url = 'https://www.investing.com'

###################################
import requests

req = requests.get(url)
print(req)  # <Response [403]>

###################################
import cloudscraper

scraper = cloudscraper.create_scraper()  # returns a CloudScraper instance

ret = scraper.get(url)
print(ret) # <Response [200]>
  1. [NOT OK] https://api.investing.com/api/financialdata/historical/43365?start-date=2022-08-19&end-date=2022-09-17&time-frame=Daily&add-missing-rows=false
url = 'https://api.investing.com/api/financialdata/historical/43365?start-date=2022-08-19&end-date=2022-09-17&time-frame=Daily&add-missing-rows=false'

###################################
import requests

req = requests.get(url)
print(req)  # <Response [403]>

###################################
import cloudscraper

scraper = cloudscraper.create_scraper()  # returns a CloudScraper instance

ret = scraper.get(url)  
print(ret) # exception. "Cloudflare version 2 Captcha challenge"
'''
Traceback (most recent call last):
cloudscraper.exceptions.CloudflareChallengeError: Detected a Cloudflare version 2 Captcha challenge, This feature is not available in the opensource (free) version.
'''

additional reference https://splunktool.com/cloudscraperexceptionscloudflarechallengeerror-detected-a-cloudflare-version-2-challenge-error-when-i-used-cloudscraper-module-with-python

nhlsm avatar Sep 16 '22 17:09 nhlsm

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

younggotti avatar Sep 16 '22 19:09 younggotti

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

Nice @younggotti : D they forgot to burry this one, it can be a temporary solution

Exganza avatar Sep 17 '22 07:09 Exganza

We need a ID and Description tables to match each symbol, cause the routine search-quotes doesn't work, yet.

Sebara0 avatar Sep 17 '22 10:09 Sebara0

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

Exganza avatar Sep 17 '22 11:09 Exganza

Hello,

I've got the same error with \investpy\bonds.py:596 in get_bond_historical_data raise ConnectionError(

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

gemo911 avatar Sep 17 '22 13:09 gemo911

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

Thank you very much. It's completaly useful. We are available to replace the "search_quotes" routine, and access by each asset "investing.com" codes. It's a great news for me

Sebara0 avatar Sep 17 '22 22:09 Sebara0

I its not working, plz fix it or show us how to fix it

woreom avatar Sep 18 '22 04:09 woreom