python yahoo weather xml parse works with 2.7.1 but not 2.6.1 -
#!/usr/bin/env python import subprocess import urllib xml.dom import minidom city_id = '23396898' temp_type = 'c' weather_url = 'http://xml.weather.yahoo.com/forecastrss?w=' + city_id +' &u=' + temp_type weather_ns = 'http://xml.weather.yahoo.com/ns/rss/1.0' dom = minidom.parse(urllib.urlopen(weather_url)) ycondition = dom.getelementsbytagnamens(weather_ns, 'condition')[0] current_outdoor_temp = ycondition.getattribute('temp') print(current_outdoor_temp)
this works fine when run on machine running python 2.7.1 not on machine running 2.6.1. problem actual number wrong. have verified i'm pulling elements correctly , can other numeric values without issue. run on 2.7.1 , 12 current celsius temp run in 2.6.1 , 54.
what has me more confused works fine fahrenheit in both environments. if put f temp_type work fine. i've confirmed happens on multiple machines. identical deployments issue other 2.6.1. can give me ideas why i'm getting issue?
running on mac os x in both instances.
edit: problem urllib.urlopen() not working correctly in 2.6 not sure why.
edit:
i've run elementtree same results. appears may specific environment why convert fahrenheit. odd.
import urllib xml.etree.elementtree import parse city_id = '23396898' temp_type = 'c' weather_url = 'http://xml.weather.yahoo.com/forecastrss?w=' + city_id +' &u=' + temp_type weather_ns = 'http://xml.weather.yahoo.com/ns/rss/1.0' rss = parse(urllib.urlopen(weather_url)).getroot() ycondition = rss.find('channel/item/{%s}condition' % weather_ns) print ycondition.get('temp')
if go directly url can see information directly.
http://xml.weather.yahoo.com/forecastrss?w=2496543&u=f http://xml.weather.yahoo.com/forecastrss?w=2496543&u=c
ok help. had space in url , causing problems.
weather_url = 'http://xml.weather.yahoo.com/forecastrss?w=' + city_id +' &u=' + temp_type
should be
weather_url = 'http://xml.weather.yahoo.com/forecastrss?w=' + city_id +'&u=' + temp_type
thanks @ronak led me in right direcion
Comments
Post a Comment