Error 403?Posted on: 10/13/15 07:53PM
Hi. I wrote a C# wallpaper program that grabs a random image from here every ten minutes. Worked great for a long time. Just today it started kicking back "403 Forbidden" failures though. I went into the code and went to the section that builds the URL to request the image. Copied it, pasted in my browser and got data back for the image. Any time it tries from the program though, it gets 403.
This is my code:
target = "
gelbooru.com/index.php?pa...amp;pid=0&tags=" + tagsel;
XmlDocument CountXML = new XmlDocument(); CountXML.Load(target);
XmlNodeList Countpc = CountXML.GetElementsByTagName("posts");
int totalresults = System.Convert.ToInt32(Countpc[0].Attributes["count"].Value);
if (totalresults == 0) {
retval.Add("failed", "");
} else {
int selected = rnd.Next(0, totalresults - 1);
target = "
gelbooru.com/index.php?pa...mp;limit=1&pid=" + selected.ToString() + "&tags=" + tagsel;
XmlDocument XML = new XmlDocument(); XML.Load(target);
XmlNodeList pc = XML.GetElementsByTagName("posts");
XmlNodeList nodes = XML.GetElementsByTagName("post");
byte[] imagedl = new WebClient().DownloadData(nodes[0].Attributes["file_url"].InnerText);
retval.Add("file_url", nodes[0].Attributes["file_url"].InnerText);
retval.Add("toggle", geltoggles[cfg_int["activetoggle"], 0]);
retval.Add("selection", tagsel);
retval.Add("tags", nodes[0].Attributes["tags"].InnerText);
retval.Add("id", nodes[0].Attributes["id"].InnerText);
retval.Add("width", nodes[0].Attributes["width"].InnerText);
retval.Add("height", nodes[0].Attributes["height"].InnerText);
retval.Add("rating", nodes[0].Attributes["rating"].InnerText);
retval.Add("md5", nodes[0].Attributes["md5"].InnerText);
retval.Add("image", Convert.ToBase64String(imagedl));
}
I told it to log the target URLs it built so I could test it in the browser. When I told it to pick a paper, this was the logging:
10/13/2015 8:49:34 PM: Processing paper ...
10/13/2015 8:49:36 PM:
gelbooru.com/index.php?pa...ressing%20-rating:safe%2010/13/2015 8:49:36 PM:
gelbooru.com/index.php?pa...ressing%20-rating:safe%2010/13/2015 8:49:37 PM: Exception while trying to change wallpaper:
10/13/2015 8:49:37 PM: The remote server returned an error: (403) Forbidden.
I copied the first URL and got:
<?xml version="1.0" encoding="UTF-8"?>
-<posts offset="0" count="17036">
<post source="" preview_height="84" preview_width="150" has_comments="false" has_notes="false" status="active" created_at="Tue Oct 13 17:00:24 -0500 2015" has_children="false" creator_id="79114" md5="82af2db6f2bd0e448a110a4a72a6d195" change="1444773624" width="1280" id="2883486" tags="4girls areolae ass barefoot blonde_hair blue_eyes blue_hair blush breasts brown_eyes censored feet flat_chest game_cg giga_(company) green_eyes huge_breasts izumo_kasumi_(ren'ai_phase) kagami_suzuha kumihama_yuki large_breasts legs long_hair looking_at_viewer mosaic_censoring multiple_girls navel nipples nironiro nude open_mouth panties panty_pull pink_eyes pink_hair ren'ai_phase short_hair silver_hair smile standing thighs toes tonami_kokoro towel undressing" rating="e" preview_url="
gelbooru.com/thumbnails/8...a110a4a72a6d195.jpg" sample_height="478" sample_width="850" sample_url="
gelbooru.com/samples/82/a...a110a4a72a6d195.jpg" parent_id="" file_url="
gelbooru.com/images/82/af...a110a4a72a6d195.png" score="0" height="720"/>
</posts>
Worked fine for me in IE, as did the second:
<?xml version="1.0" encoding="UTF-8"?>
-<posts offset="2371" count="21427">
<post source="
i1.pixiv.net/img-original.../32/46952216_p0.jpg" preview_height="150" preview_width="103" has_comments="false" has_notes="false" status="active" created_at="Fri Nov 07 07:15:23 -0600 2014" has_children="false" creator_id="6498" md5="02babd5e7f37938a2fc378f3ebc09335" change="1427227383" width="2000" id="2468205" tags=" 1girl absurdres bare_shoulders brown_hair collarbone green_eyes highres kotoba_noriaki navel nipples original ribs short_hair short_twintails sketch small_breasts solo twintails undressing " rating="q" preview_url="
gelbooru.com/thumbnails/0...fc378f3ebc09335.jpg" sample_height="1236" sample_width="850" sample_url="
simg4.gelbooru.com/sample...fc378f3ebc09335.jpg" parent_id="" file_url="
simg4.gelbooru.com/images...fc378f3ebc09335.jpg" score="7" height="2909"/>
</posts>
Any idea what's up with that? Thanks!