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

not enough information in SGMLParseError #41156

Closed
ezust mannequin opened this issue Nov 9, 2004 · 3 comments
Closed

not enough information in SGMLParseError #41156

ezust mannequin opened this issue Nov 9, 2004 · 3 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ezust
Copy link
Mannequin

ezust mannequin commented Nov 9, 2004

BPO 1063229
Nosy @devdanzin

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2009-04-22.16:03:37.351>
created_at = <Date 2004-11-09.16:54:37.000>
labels = ['type-feature', 'library']
title = 'not enough information in SGMLParseError'
updated_at = <Date 2009-04-22.16:03:37.340>
user = 'https://bugs.python.org/ezust'

bugs.python.org fields:

activity = <Date 2009-04-22.16:03:37.340>
actor = 'ajaksu2'
assignee = 'none'
closed = True
closed_date = <Date 2009-04-22.16:03:37.351>
closer = 'ajaksu2'
components = ['Library (Lib)']
creation = <Date 2004-11-09.16:54:37.000>
creator = 'ezust'
dependencies = []
files = []
hgrepos = []
issue_num = 1063229
keywords = []
message_count = 3.0
messages = ['23075', '23076', '86303']
nosy_count = 2.0
nosy_names = ['ezust', 'ajaksu2']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue1063229'
versions = ['Python 2.7']

@ezust
Copy link
Mannequin Author

ezust mannequin commented Nov 9, 2004

When SGMLParser encounters a badly formed webpage, it
throws sgmllib.SGMLParseError with a cryptic message:

[bin] > python sgmlparsertest.py
Pythonlib's error message: expected name token

I think it should give the line and offset, and maybe
even the text it had problems with, in the args of the
exception. And print it out in the message.

My extra information: error at line 1 offset 2
<head>
^
[bin]

I tried to print it out by using parser.getpos() but it
returns values which do not correspond to the error.
How do I determine this at runtime?

testcase that reproduces this problem attached.

@ezust ezust mannequin added stdlib Python modules in the Lib dir labels Nov 9, 2004
@ezust
Copy link
Mannequin Author

ezust mannequin commented Nov 9, 2004

Logged In: YES
user_id=935841

import sgmllib, urllib, urlparse
from sgmllib import SGMLParser


if __name__ == "__main__":
    url = "http://www.cs.uvic.ca/~gshoja/"
    parser = SGMLParser()
    data = urllib.urlopen(url).read()
try:
    parser.feed(data)
except sgmllib.SGMLParseError, ex:
    print "Pythonlib's error message: " + str(ex)
    line, offset = parser.getpos()
    lines = parser.rawdata.split("\\n")
    print "My extra information: error at line %d offset

%d" % parser.getpos()
print lines[line]
print "%*s" % (offset, "^")
parser = None

@devdanzin devdanzin mannequin added type-feature A feature request or enhancement labels Feb 14, 2009
@devdanzin
Copy link
Mannequin

devdanzin mannequin commented Apr 22, 2009

Closing, the message does currently include the problematic text. The
output in both 2.5 and trunk is:
Pythonlib's error message: expected name token at '<!<img src="image/at'

@devdanzin devdanzin mannequin closed this as completed Apr 22, 2009
@devdanzin devdanzin mannequin closed this as completed Apr 22, 2009
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

0 participants