1

I am getting the below exception while creating an HTTP connection.

2017-08-07 17:07:43,219 ERROR au.com.scraper.sites.ScraperSite - Exception in parsing Categories: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 403 Forbidden" at line number 153
java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 403 Forbidden"
    at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2085)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:563)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:540)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:227)
    at org.jsoup.helper.HttpConnection.get(HttpConnection.java:216)
    at org.jsoup.Jsoup.parse(Jsoup.java:183)
    at au.com.scraper.sites.ScraperSite.getCategories(ScraperSite.java:127)
    at au.com.scraper.sites.AScraperSites.execute(AScraperSites.java:74)
    at au.com.scraper.Scraper.main(Scraper.java:88)

Below is my proxy configuration.

Authenticator.setDefault(new ProxyAuthenticator("user_name", "password"));
System.setProperty("https.proxyHost", server);
System.setProperty("https.proxyPort", port);
System.setProperty("http.proxyHost", server);
System.setProperty("http.proxyPort", port);

Below is my Proxy Authenticator class.

package au.com.scraper;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
public class ProxyAuthenticator extends Authenticator
{
    public ProxyAuthenticator(String user, String password)
    {
        this.user = user;
        this.password = password;
    }
    protected PasswordAuthentication getPasswordAuthentication()
    {
        return new PasswordAuthentication(user, password.toCharArray());
    }
    private String user;
    private String password;
}

Can any one suggest why this issue is happening?

aravind
  • 542
  • 1
  • 10
  • 27
  • have you tried disabling disabledSchemes? https://stackoverflow.com/a/41806109/6503002 – amicoderozer Aug 07 '17 at 07:44
  • Could you please also post the code of your `ProxyAuthenticator` class. – SubOptimal Aug 07 '17 at 07:44
  • @SubOptimal ... I have updated the ProxyAuthenticator class. – aravind Aug 08 '17 at 00:08
  • 1
    Code is correct. The username and/or password are incorrect. Or maybe JSoup replaces your `Authenticator`, which would mean it has some other API you need to use. – user207421 Aug 08 '17 at 00:14
  • @EJP Thanks for your comments. the code is correct. If the user name/ password is updated, the JVM needs to be restarted. I have restarted my machine and surprisingly it worked. – aravind Aug 09 '17 at 01:32
  • The JVM doesn't *have* to be restarted: the application needs to be told about it, and needs to install a new `Authenticator`. – user207421 Aug 09 '17 at 01:50

1 Answers1

0

Your proxy server might be blocking that web address, we might face this issue when the web address is local address and your proxy server will be blocking that.

Venkat
  • 11
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/27770393) – EJoshuaS - Reinstate Monica Dec 04 '20 at 16:24