This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: AttributeError: 'Weather' object has no attribute 'dom'
Type: behavior Stage: resolved
Components: Library (Lib), XML Versions: Python 3.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, tc, xiang.zhang
Priority: normal Keywords:

Created on 2015-09-28 02:26 by tc, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg251742 - (view) Author: Tony (tc) Date: 2015-09-28 02:26
The source code for ctw (CurseTheWeather) can be found here: https://github.com/tdy/ctw

Running `ctw USCA0987` or `ctw --nometric USCA0987` (happens regardless of location) results in an attribute error with Python 3.4.3. Running `ctw` by itself does print a *Welcome to "Curse the Weather" Version 0.6* message.

Traceback (most recent call last):
  File "/usr/bin/ctw", line 378, in 
    curses.wrapper(main)
  File "/usr/lib/python3.4/curses/__init__.py", line 94, in wrapper
    return func(stdscr, *args, **kwds)
  File "/usr/bin/ctw", line 283, in main
    update(stdscr)
  File "/usr/bin/ctw", line 250, in update
    weather = weatherfeed.Weather(location, metric)
  File "/usr/lib/python3.4/weatherfeed.py", line 40, in __init__
    self.dom = parseString(self._getData())
  File "/usr/lib/python3.4/xml/dom/minidom.py", line 1970, in parseString
    return expatbuilder.parseString(string)
  File "/usr/lib/python3.4/xml/dom/expatbuilder.py", line 925, in parseString
    return builder.parseString(string)
  File "/usr/lib/python3.4/xml/dom/expatbuilder.py", line 223, in parseString
    parser.Parse(string, True)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 64, column 26
Exception ignored in: >
Traceback (most recent call last):
  File "/usr/lib/python3.4/weatherfeed.py", line 44, in __del__
    self.dom.unlink()
AttributeError: 'Weather' object has no attribute 'dom'

I did notice the API URL in weatherfeed.py gives a Bad Request error for:

urlHandle = urllib.request.urlopen('http://xoap.weather.com/weather/local/%s?cc=1&dayf=5&prod=xoap&link=xoap&unit=%s&par=1003666583&key=4128909340a9b2fc'

I also noticed the weather.com API now redirects to wunderground.com so I registered a new API and updated the URL in weatherfeed.py only to still get the same AttributeError. 

The new API is something like http://api.wunderground.com/api/APIKEY/conditions/q/CA/San_Francisco.json
msg251749 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2015-09-28 06:48
I don't think this is a bug of Python. You should check your own
application to make sure you are parsing the right XML.

I run your code with the old uri and get the same traceback. The
cause is you are using xml parser to parse a html document which
is error prone, since the api is out-of-date and return a html
document.

I don't know what happens about the new api since I have no KEY
and can not do the experiment. But from the api you give,
what you will retrieve is a json. Surly parse it with a xml parse
leads to error and the attribute dom won't be created.
msg251756 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015-09-28 10:03
Thanks for the report, but this looks like a bug in the cfw project. Please report it to the ctw bug tracker.
History
Date User Action Args
2022-04-11 14:58:21adminsetgithub: 69440
2015-09-28 10:03:36berker.peksagsetstatus: open -> closed

type: crash -> behavior

nosy: + berker.peksag
messages: + msg251756
resolution: not a bug
stage: resolved
2015-09-28 06:48:24xiang.zhangsetnosy: + xiang.zhang
messages: + msg251749
2015-09-28 02:26:34tccreate