Unable to Resolve XML URL (Even though it is valid)

Hey y’all, I’m trying to fetch an xml document from a URL for a daily quote, but despite the link working outside of Processing (it resolves in my browser and in an online xml reader), I’m getting lots of strange errors when I try in Processing.

XML x;

void setup() {
  size(400, 400);
  background(255);
  
  x = loadXML("https://www.chabad.org/tools/rss/dailyquote_rss.xml");
  
}

void draw() {
  saveXML(x, "save.xml");
  noLoop();
}

Here are the errors I get:

java.io.IOException: Server returned HTTP response code: 403 for URL: https://www.chabad.org/tools/rss/dailyquote_rss.xml
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1944)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1939)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1938)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1508)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
at processing.core.PApplet.createInputRaw(PApplet.java:7152)
at processing.core.PApplet.createInput(PApplet.java:7098)
at processing.core.PApplet.createReader(PApplet.java:6904)
at processing.core.PApplet.loadXML(PApplet.java:5995)
at processing.core.PApplet.loadXML(PApplet.java:5985)
at XML_test.setup(XML_test.java:28)
at processing.core.PApplet.handleDraw(PApplet.java:2425)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: https://www.chabad.org/tools/rss/dailyquote_rss.xml
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1894)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:347)
at processing.core.PApplet.createInputRaw(PApplet.java:7145)
… 8 more
The file “https://www.chabad.org/tools/rss/dailyquote_rss.xml” is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
NullPointerException

I’ve tried to resolve some sample xml URLs, and some of them worked, but others do not. Any ideas why or how I can get this working?

Much appreciated <3

1 Like

I appreciate the reference. I had researched all of this before writing this ticket though :confused: it still doesn’t explain why Processing specifically is having trouble with accessing the link, or give any ideas to how to fix it.
Networking isn’t my strong suit so I’d appreciate any help with this

Neither mine. :expressionless:

Perhaps they’ve prohibited your request due to lack of some headers or credentials. :id:

This library should be more fitted for such complex requests: :books:

Or you may try to write it in p5js instead: :flushed:

1 Like

Thanks <3 I’ll take a look

Do you have any form of network proxy involved where you’re testing?

@neilcsmith I do, I use a VPN, but I’ve turned it off and even connected to another network just to make sure. Same results.

This is working for me! :slight_smile: thanks so much. Still no clue why the normal way isn’t working, but I can have this for now. Thanks again.

1 Like

Just a thought, because the JVM can have issues with proxies. Anyway, found the answer to your problem now I’m at my computer, and it’s a fun one - try this

XML x;

void setup() {
  size(400, 400);
  System.setProperty("http.agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0");
  
  background(255);
  
  x = loadXML("https://www.chabad.org/tools/rss/dailyquote_rss.xml");
 
}

void draw() {
  //saveXML(x, "save.xml");
  println(x);
  noLoop();
}

Looks like they’re rejecting some user agents!

3 Likes

Nice finding! But I’ve also found out any “user agent” string will do for this site: :rofl:

static final String
  AGENT = "http.agent", 

  URL =
  "http://" +
  "Chabad.org/" +
  "tools/rss/" +
  "dailyquote_rss.xml";

XML xml;

void setup() {
  System.setProperty(AGENT, JAVA2D);
  println(URL, ENTER);

  xml = loadXML(URL);
  println(xml);

  exit();
}

Lol that’s too funny. I’m probably gonna end up having some fun and make my useragent some Gucci brand smart fridge browser or something. Anyways thanks fellas and be well

2 Likes