Finnhub-Stock-API / finnhub-python

Finnhub Python API Client. Finnhub API provides institutional-grade financial data to investors, fintech startups and investment firms. We support real-time stock price, global fundamentals, global ETFs holdings and alternative data. https://finnhub.io/docs/api
https://finnhub.io/
Apache License 2.0
585 stars 101 forks source link

Options Chain command (options_chain) errors out while retrieving information #16

Closed sher85 closed 4 years ago

sher85 commented 4 years ago

while using the options.chain command in jupyter notebook, the code block displayed at the end of this issue errors out. In the error description, I can read the following

FinnhubRequestException: FinnhubRequestException: Invalid Response:

followed by the actual information I was requesting which is too lengthy to show here. The code producing this error is this:

import finnhub
import os
finnhub_client = finnhub.Client(api_key=os.environ['FINNHUB_KEY'])

test = finnhub_client.option_chain(symbol='TSLA')
KurtPrice commented 4 years ago

I've been seeing the same issue. I'm not sure why this is happening. I'm going to look into a fix myself. My initial thoughts are that the validation on responses is incorrect and throwing this exception erroneously. Using the API documentation I was able to find https://finnhub.io/api/v1/stock/option-chain?symbol=TSLA which works without an API key in my browser. So in the mean time it may just be best to setup something with bs4 to grab the info from https.

If you have any ideas that are causing this issue, let me know here. I'd be excited to actually resolve this issue.

KurtPrice commented 4 years ago

Okay, so I figured out the root cause. It turns out that the api is returning the message without encoding. i.e. content-type = 'text/plain'.

client.py:L52 with raise the exception that we see here. In the mean time you can add an if statement to handle this specific call. I have a hunch that this is the expected behavior by the client, and the real issue lies with the API not setting the content-type to be application/json.

I'll make a pull request either way to fix this.

KurtPrice commented 4 years ago

Pull request I mentioned above: https://github.com/Finnhub-Stock-API/finnhub-python/pull/18 @nongdenchet

nongdenchet commented 4 years ago

hey guys I have been busy recently. Let's me have a look

nongdenchet commented 4 years ago

Please upgrade your library to 2.2.1 to get the fix

nongdenchet commented 4 years ago

I have tested and confirmed that the issue is fixed for me. Thank you @KurtPrice