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.request.urlopen documentation falsely guarantees that a URLError will be raised on errors #66986

Closed
JoshuaChin mannequin opened this issue Nov 4, 2014 · 9 comments
Labels
docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@JoshuaChin
Copy link
Mannequin

JoshuaChin mannequin commented Nov 4, 2014

BPO 22797
Nosy @orsenthil, @bitdancer
Files
  • urlopen_doc.patch
  • urlopen_doc.patch: Documents when ValueError is raised
  • urlopen_doc.patch: Note that only protocol errors raise UrlError
  • 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 2016-06-04.00:19:22.160>
    created_at = <Date 2014-11-04.17:04:57.606>
    labels = ['type-bug', 'docs']
    title = 'urllib.request.urlopen documentation falsely guarantees that a URLError will be raised on errors'
    updated_at = <Date 2016-06-04.05:31:34.740>
    user = 'https://bugs.python.org/JoshuaChin'

    bugs.python.org fields:

    activity = <Date 2016-06-04.05:31:34.740>
    actor = 'python-dev'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2016-06-04.00:19:22.160>
    closer = 'r.david.murray'
    components = ['Documentation']
    creation = <Date 2014-11-04.17:04:57.606>
    creator = 'Joshua.Chin'
    dependencies = []
    files = ['37129', '37131', '43131']
    hgrepos = []
    issue_num = 22797
    keywords = ['patch']
    message_count = 9.0
    messages = ['230640', '230641', '230657', '267000', '267115', '267151', '267195', '267196', '267235']
    nosy_count = 6.0
    nosy_names = ['orsenthil', 'r.david.murray', 'docs@python', 'python-dev', 'Joshua.Chin', 'alex_thebear']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue22797'
    versions = ['Python 3.5', 'Python 3.6']

    @JoshuaChin
    Copy link
    Mannequin Author

    JoshuaChin mannequin commented Nov 4, 2014

    The documentation for urlopen states that it "Raises URLError on errors." However, urlopen can raise a ValueError. In fact, test_urllib. urlopen_FileTests.test_relativelocalfile specifically checks if urlopen raises a ValueError. I suggest removing the guarantee from the documentation.

    @JoshuaChin JoshuaChin mannequin assigned docspython Nov 4, 2014
    @JoshuaChin JoshuaChin mannequin added docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error labels Nov 4, 2014
    @bitdancer
    Copy link
    Member

    This is a general principle in Python. A module may raise specific errors, but there are always other errors that may be raised. The wording could be clarified, but it should not be removed.

    @bitdancer
    Copy link
    Member

    (Looking at your new patch...thanks for giving it a try even though I wasn't clear).

    There are lots of other errors it can raise, too. I was thinking more along the lines of "raises URLError on http protocol errors". The problem is that's not completely accurate, either, but I don't remember exactly when it is that HTTPError can leak through.

    Just for reference, in my code that calls urlopen and needs to keep running it if can't access the URL no matter what the (network-derived) reason, I catch ConnectionError, HTTPError, URLError, and IncompleteRead.

    We do not document all possible exceptions. We document those that are specific to the module in question (which is URLError in this case) or that are part of the documented API (such as mentioning TimeoutError as what happens if the timeout specified by a timeout keyword is exceeded).

    ValueErrors are a general class of errors that, when encountered, usually mean you need to fix your code (or, in the case of the SSL one you mention, check for SSL support at startup, assuming I understood correctly), rather than something you would catch around the urlopen call in a typical program. There are, of course, occasions when you *do* catch ValueErrors in specific bits of code, but there is no practical way we can document all of the reasons ValueError might get raised, so we don't try.

    All of that said, it would be lovely to have a reference somewhere (maybe a tutorial?) that went over all the possible exceptions one might get while using various network libraries, and why they might arise. It is an issue that comes from the fact that the libraries are built on top of each other and the general python technique is that lower level errors are allowed to bubble up. It would be a beast to keep up to date, though, which is probably one reason we don't have one. But even that kind of guide wouldn't include ValueErrors.

    @alexthebear
    Copy link
    Mannequin

    alexthebear mannequin commented Jun 3, 2016

    Fixed the docs to specifically note that only protocol related errors raise the UrlError exception.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 3, 2016

    New changeset aed4b9981fca by R David Murray in branch '3.5':
    bpo-22797: clarify when URLErrors are raised by urlopen.
    https://hg.python.org/cpython/rev/aed4b9981fca

    New changeset d085b4f779af by R David Murray in branch '3.5':
    Merge: bpo-22797: clarify when URLErrors are raised by urlopen.
    https://hg.python.org/cpython/rev/d085b4f779af

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 3, 2016

    New changeset 8b6b6add8e47 by R David Murray in branch 'default':
    psuedo merge: bpo-22797: clarify when URLErrors are raised by urlopen.
    https://hg.python.org/cpython/rev/8b6b6add8e47

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 4, 2016

    New changeset b4df20312b78 by R David Murray in branch 'default':
    Clean up urlopen doc string.
    https://hg.python.org/cpython/rev/b4df20312b78

    @bitdancer
    Copy link
    Member

    Thanks, Alexander.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 4, 2016

    New changeset 2d69d0419879 by Martin Panter in branch 'default':
    Issue bpo-22797: Synchronize urlopen() doc string with RST documentation
    https://hg.python.org/cpython/rev/2d69d0419879

    @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
    docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant