finance-api:socketexception:权限被拒绝

7rtdyuoh  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(263)

所以我正试图写我的第一个程序,从网上提取数据,因为这是一个金融程序,我决定使用(据称)简单易用的雅虎!财务api。我下载了api.jar文件,为了保存,我通过addexternaljars工具将它们全部导入eclipse。
问题是,每当我尝试运行它时,都会遇到一个socketexception:permission denied runtime错误。
我运行的代码非常基本:

Stock stock = YahooFinance.get("ORCL");

这一行代码应该可以从YahooFinance获得oracle(orcl)股票的价值。相反,它抛出异常。
我想尽一切办法:
1) 我禁用了防火墙2)我仔细检查了我的.jar导入3)我测试运行这一行作为一个单独的线程的一部分(一个绝望的,盲目的举动,但我达到了那个点)。
我已经用尽了我所能想到的所有可能的研究Angular ,到目前为止我所发现的就是:使用jsp发送电子邮件
这看起来是一个非常类似的问题,所以我尝试了建议的解决方案:在eclipse.ini文件中添加“-djava.net.preferipv4stack=true”行。似乎没有效果。
以防万一,我也将eclipse.ini文件的内容粘贴在这里,以防万一我把它放错了位置或其他什么:

-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20140603-1326
-product
org.eclipse.epp.package.standard.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Djava.net.preferIPv4Stack=true
-Dosgi.requiredJavaVersion=1.7
-Xms40m
-Xmx512m

我现在没主意了。我只想知道为什么会抛出这个异常,以及我能做些什么来防止它。
提前谢谢。
编辑:根据请求,完整堆栈跟踪。

Apr 27, 2015 11:54:35 PM yahoofinance.quotes.QuotesRequest getResult
INFO: Sending request: http://finance.yahoo.com/d/quotes.csv?s=ORCL&f=nsc4xab2sa5sbb3sb6sl1sk3sd1t1opghva2kjm3m4sj2sss1sj1sf6sr1qdyee7e9e8rr5p6p5b4s6j4t8&e=.csv
Apr 27, 2015 11:54:35 PM yahoofinance.quotes.QuotesRequest getResult
SEVERE: java.net.SocketException: Permission denied: connect
java.net.SocketException: Permission denied: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.<init>(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at yahoofinance.quotes.QuotesRequest.getResult(QuotesRequest.java:83)
    at yahoofinance.YahooFinance.getQuotes(YahooFinance.java:332)
    at yahoofinance.YahooFinance.get(YahooFinance.java:76)
    at yahoofinance.YahooFinance.get(YahooFinance.java:61)
    at currency.CurrencyConverter.createWindow(CurrencyConverter.java:35)
    at currency.CurrencyConverter.<init>(CurrencyConverter.java:25)
    at currency.CurrencyDriver$1.run(CurrencyDriver.java:10)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
rbpvctlc

rbpvctlc1#

我想我也遇到了同样的问题:有时这需要一点努力,但我设法得到了我想要的信息,我是说,有点无聊,我的意思是,递归地:

void searchQuote(symbol) throws InterruptedException {
    try{
        Stock stock = YahooFinance.get(symbol);
    }catch(Exception e){
        if(e.getClass().getName().equals("java.net.SocketException") ||
                 e.getClass().getName().equals("java.net.SocketTimeoutException")){
            Thread.sleep(60000);
            searchQuote(symbol);
        }
    }
}

对我来说,成功了。

相关问题