Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to parse an illformed geo feed #305

Closed
n3s7or opened this issue Mar 25, 2022 · 0 comments
Closed

Failed to parse an illformed geo feed #305

n3s7or opened this issue Mar 25, 2022 · 0 comments

Comments

@n3s7or
Copy link

n3s7or commented Mar 25, 2022

When trying to parse a feed an KeyError: 'where' occurred.

View complete traceback

/<project_location>/venv/bin/python main.py
Traceback (most recent call last):
  File "main.py", line 28, in <module>
    main()
  File "main.py", line 22, in main
    feed = feedparser.parse(tmp)
  File "/<project_location>/venv/lib/python3.8/site-packages/feedparser/api.py", line 263, in parse
    saxparser.parse(source)
  File "/usr/lib/python3.8/xml/sax/expatreader.py", line 111, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "/usr/lib/python3.8/xml/sax/xmlreader.py", line 125, in parse
    self.feed(buffer)
  File "/usr/lib/python3.8/xml/sax/expatreader.py", line 217, in feed
    self._parser.Parse(data, isFinal)
  File "../Modules/pyexpat.c", line 407, in StartElement
  File "/usr/lib/python3.8/xml/sax/expatreader.py", line 369, in start_element_ns
    self._cont_handler.startElementNS(pair, None,
  File "/<project_location>/venv/lib/python3.8/site-packages/feedparser/parsers/strict.py", line 103, in startElementNS
    self.unknown_starttag(localname, list(attrsD.items()))
  File "/<project_location>/venv/lib/python3.8/site-packages/feedparser/mixin.py", line 289, in unknown_starttag
    return method(attrs_d)
  File "/<project_location>/venv/lib/python3.8/site-packages/feedparser/namespaces/georss.py", line 98, in _start_gml_point
    self._parse_srs_attrs(attrs_d)
  File "/<project_location>/venv/lib/python3.8/site-packages/feedparser/namespaces/georss.py", line 94, in _parse_srs_attrs
    context['where']['srsName'] = srs_name
  File "/<project_location>/venv/lib/python3.8/site-packages/feedparser/util.py", line 113, in __getitem__
    return dict.__getitem__(self, key)
KeyError: 'where'

Process finished with exit code 1

I didn't find nothing relevant in the project's issues or SO, only this question which is basically the very same issue.

The problem seems the absent of where tag from georss namespace.

How to replicate in unittests:

<!--
Description: item point where
Expect: entries[0]['where']['type'] == 'Point' and entries[0]['where']['coordinates'] == (31.1732, 36.9382)
-->
<feed
  xmlns="http://www.w3.org/2005/Atom"
  xmlns:gml="http://www.opengis.net/gml"
  >
  <entry>
   <gml:Point>
     <gml:pos>36.9382 31.1732</gml:pos>
   </gml:Point>
  </entry>
</feed>

Unittest result

======================================================================
ERROR: test_000000 (__main__.TestCase)
./tests/illformed/geo/gml_point.xml: item point where
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/runtests.py", line 916, in fn
    self.fail_unless_eval(xmlfile, eval_string)
  File "tests/runtests.py", line 173, in fail_unless_eval
    env = feedparser.parse(xmlfile)
  File "/<---->/feedparser/.tox/py38/lib/python3.8/site-packages/feedparser/api.py", line 282, in parse
    saxparser.parse(source)
  File "/usr/lib/python3.8/xml/sax/expatreader.py", line 111, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "/usr/lib/python3.8/xml/sax/xmlreader.py", line 125, in parse
    self.feed(buffer)
  File "/usr/lib/python3.8/xml/sax/expatreader.py", line 217, in feed
    self._parser.Parse(data, isFinal)
  File "../Modules/pyexpat.c", line 407, in StartElement
  File "/usr/lib/python3.8/xml/sax/expatreader.py", line 369, in start_element_ns
    self._cont_handler.startElementNS(pair, None,
  File "/<---->/feedparser/.tox/py38/lib/python3.8/site-packages/feedparser/parsers/strict.py", line 103, in startElementNS
    self.unknown_starttag(localname, list(attrsD.items()))
  File "/<---->/feedparser/.tox/py38/lib/python3.8/site-packages/feedparser/mixin.py", line 292, in unknown_starttag
    return method(attrs_d)
  File "/<---->/feedparser/.tox/py38/lib/python3.8/site-packages/feedparser/namespaces/georss.py", line 98, in _start_gml_point
    self._parse_srs_attrs(attrs_d)
  File "/<---->/feedparser/.tox/py38/lib/python3.8/site-packages/feedparser/namespaces/georss.py", line 94, in _parse_srs_attrs
    context['where']['srsName'] = srs_name
  File "/<---->/feedparser/.tox/py38/lib/python3.8/site-packages/feedparser/util.py", line 114, in __getitem__
    return dict.__getitem__(self, key)
KeyError: 'where'

n3s7or pushed a commit to n3s7or/feedparser that referenced this issue Mar 25, 2022
Rongronggg9 pushed a commit to Rongronggg9/feedparser that referenced this issue May 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant