finnhub-python icon indicating copy to clipboard operation
finnhub-python copied to clipboard

finnhub_client.option_chain() command: raise FinnhubRequestException error

Open aniqueakhtar opened this issue 8 months ago • 0 comments

This code was working previously. Error started about a week ago. I updated to version 2.4.18, but the error still persists.

The following code:

finnhub_api_key = "XYZ"
finnhub_client = finnhub.Client(api_key=finnhub_api_key)
all_options = finnhub_client.option_chain(symbol='TSLA').

Gives this error:

  File "<stdin>", line 1, in <module>
  File "site-packages\finnhub\client.py", line 136, in option_chain
    return self._get("/stock/option-chain", params=params)
  File "site-packages\finnhub\client.py", line 71, in _get
    return self._request("get", path, **kwargs)
  File "site-packages\finnhub\client.py", line 41, in _request
    return self._handle_response(response)
  File "site-packages\finnhub\client.py", line 56, in _handle_response
    raise FinnhubRequestException("Invalid Response: {}".format(response.text))
finnhub.exceptions.FinnhubRequestException: FinnhubRequestException: Invalid Response: <!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="author" content="Finnhub.io"/>

    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
    <link rel="shortcut icon"
          href="/static/img/webp/finnhub-logo.webp"/>


    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-64068110-3"></script>
    <script>
      window.dataLayer = window.dataLayer || [];

      function gtag() {
        dataLayer.push(arguments);
      }

      gtag('js', new Date());

      gtag('config', 'UA-64068110-3');
    </script>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js'></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.0/umd/react.production.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.0/umd/react-dom.production.min.js"></script>

    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.0.0/css/all.css">

    <script src="https://cdnjs.cloudflare.com/ajax/libs/waypoints/4.0.1/jquery.waypoints.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.3.1/redux.min.js"></script>
    <script src="https://unpkg.com/[email protected]/dist/react-redux.min.js"></script>
    <script type="text/javascript">

      var protocol = location.protocol;
      var wsprotocol
      if (protocol === "https:") {
        wsprotocol = "wss:";
      } else {
        wsprotocol = "ws:";
      }
      var slashes = protocol.concat("//");
      var host = slashes.concat(window.location.host);

      window.wsUrl = ""
      if (window.wsUrl === '') {
        window.wsUrl = window.location.host
      }

      window.getCookie = function getcookie(cname) {
        var name = cname + "=";
        var decodedCookie = decodeURIComponent(document.cookie);
        var ca = decodedCookie.split(';');
        for (var i = 0; i < ca.length; i++) {
          var c = ca[i];
          while (c.charAt(0) == ' ') {
            c = c.substring(1);
          }
          if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
          }
        }
        return "";
      }

      window.setCookie = function setcookie(cname, cvalue, exdays) {
        var d = new Date();
        d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
        var expires = "expires=" + d.toUTCString();
        document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
      }

      window.toTitle = function toTitleCase(str) {
        return str.replace(/\w\S*/g, function (txt) {
          return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
        });
      }

      window.getUrlParams = function (key) {
        let url = location.href
        var params = {};
        (url + '?').split('?')[1].split('&').forEach(function (pair) {
          pair = (pair + '=').split('=').map(decodeURIComponent);
          if (pair[0].length) {
            params[pair[0]] = pair[1];
          }
        });
        return params[key];
      };

      window.stripHtml = function (html) {
        let tmp = document.createElement("DIV");
        tmp.innerHTML = html;
        return tmp.textContent || tmp.innerText || "";
      }

      window.timeConverter = function tConverter(UNIX_timestamp) {
        var a = new Date(UNIX_timestamp * 1000);
        var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
        var dates = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
        var month = months[a.getMonth()];
        var date = a.getDate();
        var time = dates[a.getDay()] + ' ' + month + ' ' + date
        return time;
      }

      window.roundToX = function (num, X) {
        return +(Math.round(num + "e+" + X) + "e-" + X);
      }
    </script>


    <meta name="description"
      content="Finnhub - Free stock API for realtime market data, global company fundamentals, economic data, and alternative data."/>
<meta name="keywords"
      content="stock api,realtime,stock,equity,forex,crypto,fundamental data,economic data,alternative data">
<meta property="og:title" content="Finnhub - Free realtime APIs for stock, forex and cryptocurrency.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://finnhub.io/">
<meta property="og:image"
      content="https://static.finnhub.io/img/finnhub_2020-05-09_20_51/logo/logo-transparent-thumbnail.png">
<meta property="og:description"
      content="Finnhub - Free APIs for realtime stock, forex, and cryptocurrency. Company fundamentals, Economic data, and Alternative data.">
<meta name="twitter:card" content="summary">
<meta name="twitter:title"
      content="Finnhub - Free realtime APIs for stock, forex and cryptocurrency.">
<meta name="twitter:image"
      content="https://static.finnhub.io/img/finnhub_2020-05-09_20_51/logo/logo-transparent-thumbnail.png">
<meta name="twitter:description"
      content="Finnhub - Free APIs for realtime stock, forex, and cryptocurrency. Company fundamentals, Economic data, and Alternative data.">
<meta charset="UTF-8">

    <title>Finnhub Stock APIs - Real-time stock prices, Company fundamentals, Estimates, and Alternative data.</title>

    <script type="text/javascript">
      window.serverData = {"announcement":"Global Filings, Transcripts, and Presentations data are available on Finnhub API. Check out \u003ca href=\"/docs/api/earnings-call-transcripts-api\"\u003ehere\u003c/a\u003e"}
      window.login =  false
      window.isSubscribe = null
    </script>
</head>
<body>
<div id="root"></div>
<script type="text/javascript" src="/static/js/webpack/dist/main-index.bundle.f79db3b0f28c064166b8.js"></script></body>
</html>

aniqueakhtar avatar May 09 '25 03:05 aniqueakhtar