Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.StringIndexOutOfBoundsException: String index out of range: -1 #44

Closed
yogamurthy opened this issue Apr 10, 2016 · 7 comments
Closed
Assignees

Comments

@yogamurthy
Copy link

Source:

package asd.cc;

import java.io.IOException;
import java.math.BigDecimal;

import yahoofinance.Stock;
import yahoofinance.YahooFinance;

public class Sstocks {

public static void main (String[] args)
{

    try {
        Stock stock = YahooFinance.get("INTC");

        stock.print();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        System.out.println("error: "+e);
    }
}

}

Error 👍
Apr 10, 2016 11:02:38 AM yahoofinance.quotes.QuotesRequest getResult
INFO: Sending request: http://finance.yahoo.com/d/quotes.csv?s=INTC&f=nsc4xab2sa5sbb3sb6sl1sk3sd1t1opghva2kjm3m4sj2sss1sj1sf6sr1qdyee7e9e8rr5p6p5b4s6j4t8s7&e=.csv
Apr 10, 2016 11:02:38 AM yahoofinance.quotes.QuotesRequest getResult
INFO: Parsing CSV line:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at yahoofinance.quotes.stock.StockQuotesRequest.parseCSVLine(StockQuotesRequest.java:126)
at yahoofinance.quotes.stock.StockQuotesRequest.parseCSVLine(StockQuotesRequest.java:11)
at yahoofinance.quotes.QuotesRequest.getResult(QuotesRequest.java:95)
at yahoofinance.YahooFinance.getQuotes(YahooFinance.java:355)
at yahoofinance.YahooFinance.get(YahooFinance.java:85)
at yahoofinance.YahooFinance.get(YahooFinance.java:69)
at asd.cc.Sstocks.main(Sstocks.java:15)

@sstrickx sstrickx self-assigned this Apr 10, 2016
@sstrickx
Copy link
Owner

Hi,

This is really strange. The fact that the CSV line starts with INFO: Parsing CSV line: <!DOCTYPE html> indicates that something is going wrong, unrelated to the library.
There's a few possibilities I could think of:

  1. There was a temporary problem / outage for Yahoo Finance in which case they decided to show a HTML page with a warning about the outage. (not sure if that happens in case of outage)
  2. You are behind a proxy which is blocking the request and responds with a HTML page

Could you open the link in your browser to see what you get? http://finance.yahoo.com/d/quotes.csv?s=INTC&f=nsc4xab2sa5sbb3sb6sl1sk3sd1t1opghva2kjm3m4sj2sss1sj1sf6sr1qdyee7e9e8rr5p6p5b4s6j4t8s7&e=.csv

@yogamurthy
Copy link
Author

Hi, I'm able to open the link in a browser and able to get CSV downloaded. When I try it in a eclipse program, it is giving error though the same program worked a day back. I checked my proxy and its all good nothing changed recently in my system too

@sstrickx
Copy link
Owner

Sorry, no idea what the problem is. This should work. Could you give it a try without the proxy?
It's possible that the proxy blocks the request from the library because it doesn't provide a known User-Agent header in the HTTP request. That would explain why it does work correctly from your browser.

@yogamurthy
Copy link
Author

I finally figured the issue, the code works but when we issue more than 1000 requests per hours then we are hitting this issue "Yahoo says you have reached the limit".

Thanks for your help though

@LucasMcQ
Copy link

I'm having the same issue. Can you provide how you fixed this?

@coderfender
Copy link

Apparently, the Yahoo Finance API is now closed and every time we hit it throws "String Index out of Bounds exception"

@sstrickx
Copy link
Owner

Please just use the latest version of the library... (3.12.3)

Repository owner locked as resolved and limited conversation to collaborators Jan 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants