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

urllib.robotparser doesn't work in Py3k #47597

Closed
mgiuca mannequin opened this issue Jul 12, 2008 · 2 comments
Closed

urllib.robotparser doesn't work in Py3k #47597

mgiuca mannequin opened this issue Jul 12, 2008 · 2 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@mgiuca
Copy link
Mannequin

mgiuca mannequin commented Jul 12, 2008

BPO 3347
Nosy @brettcannon
Files
  • robotparser.py.patch
  • 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 2008-07-18.21:00:27.948>
    created_at = <Date 2008-07-12.13:46:16.049>
    labels = ['type-bug', 'library']
    title = "urllib.robotparser doesn't work in Py3k"
    updated_at = <Date 2008-07-18.21:00:27.938>
    user = 'https://bugs.python.org/mgiuca'

    bugs.python.org fields:

    activity = <Date 2008-07-18.21:00:27.938>
    actor = 'jhylton'
    assignee = 'jhylton'
    closed = True
    closed_date = <Date 2008-07-18.21:00:27.948>
    closer = 'jhylton'
    components = ['Library (Lib)']
    creation = <Date 2008-07-12.13:46:16.049>
    creator = 'mgiuca'
    dependencies = []
    files = ['10885']
    hgrepos = []
    issue_num = 3347
    keywords = ['patch']
    message_count = 2.0
    messages = ['69586', '69989']
    nosy_count = 3.0
    nosy_names = ['jhylton', 'brett.cannon', 'mgiuca']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue3347'
    versions = ['Python 3.0']

    @mgiuca
    Copy link
    Mannequin Author

    mgiuca mannequin commented Jul 12, 2008

    urllib.robotparser is broken in Python 3.0, due to a bytes object
    appearing where a str is expected.

    Example:

    >>> import urllib.robotparser
    >>> r =
    urllib.robotparser.RobotFileParser('http://www.python.org/robots.txt')
    >>> r.read()
    TypeError: expected an object with the buffer interface

    This is because the variable f in RobotFileParser.read is opened by
    urlopen as a binary file, so f.read() returns a bytes object.

    I've included a patch, which checks if it's a bytes, and if so, decodes
    it with 'utf-8'. A more thorough fix might figure out what the charset
    of the document is (in f.headers['Content-Type']), but at least this
    works, and will be sufficient in almost all cases.

    Also there are no test cases for urllib.robotparser.

    Patch (robotparser.py.patch) is for branch /branches/py3k, revision 64891.

    Commit log:

    Lib/urllib/robotparser.py: Fixed robotparser for Python 3.0. urlopen
    returns bytes objects where str expected. Decode the bytes using UTF-8.

    @mgiuca mgiuca mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jul 12, 2008
    @jhylton
    Copy link
    Mannequin

    jhylton mannequin commented Jul 18, 2008

    Committed revision 65118.

    I applied a simple version of this patch and added a unittest.

    @jhylton jhylton mannequin closed this as completed Jul 18, 2008
    @jhylton jhylton mannequin self-assigned this Jul 18, 2008
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 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-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    0 participants