investiny: Request to Investing.com API failed with error code: 403

here is my code:

from investiny import historical_data 

data = historical_data(investing_id=19256, from_date="01/01/2019", to_date="12/31/2019") #adese 19256 data-content-id üzerinden bulunuyor

here’s out:

runfile('C:/Users/emrec/Desktop/TUBITAK 22 DOSYASI/stockrates/untitled2.py', wdir='C:/Users/emrec/Desktop/TUBITAK 22 DOSYASI/stockrates')
Traceback (most recent call last):

  File "C:\Users\emrec\AppData\Local\Programs\Python\Python39\lib\site-packages\spyder_kernels\py3compat.py", line 356, in compat_exec
    exec(code, globals, locals)

  File "c:\users\emrec\desktop\tubitak 22 dosyasi\stockrates\untitled2.py", line 3, in <module>
    data = historical_data(investing_id=6408, from_date="01/01/2019", to_date="12/31/2019") #adese 19256 data-content-id üzerinden bulunuyor

  File "C:\Users\emrec\AppData\Local\Programs\Python\Python39\lib\site-packages\investiny\historical.py", line 48, in historical_data
    info = investing_info(investing_id=investing_id)

  File "C:\Users\emrec\AppData\Local\Programs\Python\Python39\lib\site-packages\investiny\info.py", line 41, in investing_info
    return request_to_investing(  # type: ignore

  File "C:\Users\emrec\AppData\Local\Programs\Python\Python39\lib\site-packages\investiny\utils.py", line 36, in request_to_investing
    raise ConnectionError(

ConnectionError: Request to Investing.com API failed with error code: 403.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 24 (4 by maintainers)

Most upvoted comments

Hi guys! So Investing.com has some severe limitations and strict Cloudflare protection so it’s probably that, I tried to contact them in the past in order to find a solution for this, but they didn’t reply, so it seems that they are not interested at all in having an open source project to pull data from their site and/or API. I’ll probably try to contact them again, but they are reluctant to do anything, so probably it will never work as smooth as before 😭

If I may shamelessly plug my project tessa – it’s an abstraction layer on top of data sources. It used to use investpy and coingecko. Now it uses yfinance and coingecko. It offers a streamlined interface and a number of features such as a Symbol class including collections to store and load a list of symbols. Might be useful for some people.

https://info.signalsciences.com/rs/025-XKO-469/images/signal-sciences-case-study-investingcom.pdf doesn’t look like it’s gona work again any time soon. what a shame

Same issue here, tried from a remote server (different IP) in case of blacklist, and my own machine, both got 403.

@ivgomezarnedo

Amazing! Good job!

For Selenium, may be the problem is on the driver. User-Agent in http header is also an factor Cloudflare checks.

You can check on this link, https://stackoverflow.com/questions/68289474/selenium-headless-how-to-bypass-cloudflare-detection-using-selenium

@alvarobartt Can you contact me as I can share with you how to make it work 😃

So without patch I get 403 👎 but with some extra setup added I get proper responses as needed.

{ [5 bytes data]
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
{ [222 bytes data]
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
{ [222 bytes data]
* old SSL session ID is stale, removing
{ [5 bytes data]
* Connection state changed (MAX_CONCURRENT_STREAMS == 256)!
} [5 bytes data]
< HTTP/2 200
< date: Sun, 04 Jun 2023 14:57:14 GMT
< content-type: text/html; charset=utf-8
< access-control-allow-origin: https://tvc-invdn-com.investing.com
< x-requested-with: XMLHttpRequest
< access-control-allow-methods: POST, GET, OPTIONS, PUT, DELETE
< access-control-allow-headers: Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, accept, sessionid, x-csrftoken, content-type
< x-benchmark-1a: 0ms, mem alloc - 768.00Kb start
< x-benchmark-1b: 66ms, mem alloc - 1.25Mb start of TradingviewConnector::getExchanges
< x-benchmark-1c: 66ms, mem alloc - 1.25Mb get currencies in TradingviewConnector::getExchanges
< x-benchmark-1d: 184ms, mem alloc - 8.00Mb get_exchange_attr in TradingviewConnector::getExchanges
< x-benchmark-1e: 455ms, mem alloc - 9.00Mb make list in TradingviewConnector::getExchanges
< x-benchmark-1f: 456ms, mem alloc - 9.00Mb end of TradingviewConnector::getExchanges
< x-benchmark-1g: 457ms, mem alloc - 9.00Mb end
< vary: Accept-Encoding,User-Agent
< content-security-policy: upgrade-insecure-requests; block-all-mixed-content
< cf-cache-status: DYNAMIC
< set-cookie: __cf_bm=EHzHH2HOT6DJb4uLsqBH2gNwP3wdFvD9U9fubmMjR6c-1685890634-0-AZWJpSXr3ShvcdKca0E2t1T7pxeWSprj1xYrm8tggM9qcqs4VHBYloXJVYUdNa9PP6oJXtJK5b7HkQqnVSobM7Y=; path=/; expires=Sun, 04-Jun-23 15:27:14 GMT; domain=.investing.com; HttpOnly; Secure; SameSite=None
< server: cloudflare
< cf-ray: 7d2106f01cf51c18-AMS
< content-encoding: br
< alt-svc: h3=":443"; ma=86400
<
{ [103 bytes data]
100   103    0   103    0     0    147      0 --:--:-- --:--:-- --:--:--   150
* Connection #0 to host tvc6.investing.com left intact
[{"symbol":"AAPL","full_name":"NASDAQ:AAPL","description":"Apple Inc","type":"Stock","ticker":"6408","exchange":"NASDAQ"}]%