bad request - Yahoo Weather API fails to connect C# -


the yahoo weather api changed url week , app fails connect now. please see below code new url , below in comment old url.

private void getweather() {     try     {         string query = string.format("https://query.yahooapis.com/v1/public/yql?q=" + settings.default.woeid.tostring() + "&u=" + settings.default.temperature);         //string query = string.format("https://weather.yahooapis.com/forecastrss?w=" + settings.default.woeid.tostring() + "&u=" + settings.default.temperature);         xmldocument wdata = new xmldocument();         wdata.load(query);          xmlnamespacemanager man = new xmlnamespacemanager(wdata.nametable);         man.addnamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");          xmlnode channel = wdata.selectsinglenode("rss").selectsinglenode("channel");         xmlnodelist nodes = wdata.selectnodes("/query/results/channel/item/yweather:forecast", man);         //xmlnodelist nodes = wdata.selectnodes("/rss/channel/item/yweather:forecast", man);          temperature = channel.selectsinglenode("item").selectsinglenode("yweather:condition", man).attributes["temp"].value;          condition = channel.selectsinglenode("item").selectsinglenode("yweather:condition", man).attributes["text"].value;          humidity = channel.selectsinglenode("yweather:atmosphere", man).attributes["humidity"].value;          winspeed = channel.selectsinglenode("yweather:wind", man).attributes["speed"].value;          town = channel.selectsinglenode("yweather:location", man).attributes["city"].value;          tfcond = channel.selectsinglenode("item").selectsinglenode("yweather:forecast", man).attributes["text"].value;          tfhigh = channel.selectsinglenode("item").selectsinglenode("yweather:forecast", man).attributes["high"].value;          tflow = channel.selectsinglenode("item").selectsinglenode("yweather:forecast", man).attributes["low"].value;          qevent = "connected";     }     catch { qevent = "failed"; } } 

i following error:

exception: exception thrown: 'system.net.webexception' in system.dll ("the remote server returned error: (400) bad request."). exception thrown: 'system.net.webexception' in system.dll ("the remote server returned error: (400) bad request.") 12.32s [11632]

try changing url

string query = string.format("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(" + settings.default.woeid.tostring() + ")%20and%20u%20%3d%20%27" + settings.default.temperature + "%27&format=xml&env=store%3a%2f%2fdatatables.org%2falltableswithkeys"); 

edit:

i don't know documentation url.
gives

<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="1" yahoo:created="2017-07-31t17:50:38z" yahoo:lang="en-us"> <results> <channel> <yweather:units xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"  distance="mi" pressure="in" speed="mph" temperature="f"/> <title>yahoo! weather - seattle, wa, us</title> <link> http://us.rd.yahoo.com/dailynews/rss/weather/country__country/*https://weather.yahoo.com/country/state/city-2490383/ </link> <description>yahoo! weather seattle, wa, us</description> <language>en-us</language> <lastbuilddate>mon, 31 jul 2017 10:50 pdt</lastbuilddate> <ttl>60</ttl> <yweather:location xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" city="seattle" country="united states" region=" wa"/> <yweather:wind xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" chill="66" direction="0" speed="14"/> <yweather:atmosphere xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" humidity="64" pressure="1023.0" rising="0" visibility="16.1"/> <yweather:astronomy xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" sunrise="5:45 am" sunset="8:45 pm"/> <image> <title>yahoo! weather</title> <width>142</width> <height>18</height> <link>http://weather.yahoo.com</link> <url> http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif </url> </image> <item> <title>conditions seattle, wa, @ 10:00 pdt</title> <geo:lat xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">47.603561</geo:lat> <geo:long xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">-122.329437</geo:long> <link> http://us.rd.yahoo.com/dailynews/rss/weather/country__country/*https://weather.yahoo.com/country/state/city-2490383/ </link> <pubdate>mon, 31 jul 2017 10:00 pdt</pubdate> <yweather:condition xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" code="32" date="mon, 31 jul 2017 10:00 pdt" temp="66" text="sunny"/> <yweather:forecast xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" code="32" date="31 jul 2017" day="mon" high="77" low="58" text="sunny"/> <yweather:forecast xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" code="32" date="01 aug 2017" day="tue" high="80" low="60" text="sunny"/> <yweather:forecast xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" code="32" date="02 aug 2017" day="wed" high="84" low="64" text="sunny"/> <yweather:forecast xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" code="32" date="03 aug 2017" day="thu" high="87" low="67" text="sunny"/> <yweather:forecast xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" code="34" date="04 aug 2017" day="fri" high="89" low="67" text="mostly sunny"/> <yweather:forecast xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" code="30" date="05 aug 2017" day="sat" high="84" low="65" text="partly cloudy"/> <yweather:forecast xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" code="34" date="06 aug 2017" day="sun" high="79" low="65" text="mostly sunny"/> <yweather:forecast xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" code="34" date="07 aug 2017" day="mon" high="76" low="62" text="mostly sunny"/> <yweather:forecast xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" code="34" date="08 aug 2017" day="tue" high="78" low="62" text="mostly sunny"/> <yweather:forecast xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" code="34" date="09 aug 2017" day="wed" high="80" low="63" text="mostly sunny"/> <description> <![cdata[<img src="http://l.yimg.com/a/i/us/we/52/32.gif"/> <br /> <b>current conditions:</b> <br />sunny <br /> <br /> <b>forecast:</b> <br /> mon - sunny. high: 77low: 58 <br /> tue - sunny. high: 80low: 60 <br /> wed - sunny. high: 84low: 64 <br /> thu - sunny. high: 87low: 67 <br /> fri - sunny. high: 89low: 67 <br /> <br /> <a href="http://us.rd.yahoo.com/dailynews/rss/weather/country__country/*https://weather.yahoo.com/country/state/city-2490383/">full forecast @ yahoo! weather</a> <br /> <br /> (provided <a href="http://www.weather.com" >the weather channel</a>) <br /> ]]> </description> <guid ispermalink="false"/> </item> </channel> </results> </query>     <!--  total: 5  --> 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -