[Python] How do I catch a specific HTTP error in Python?

Discussão em 'Python' iniciado por Stack, Agosto 4, 2025.

  1. Stack

    Stack Membro Participativo

    I have

    import urllib2
    try:
    urllib2.urlopen("some url")
    except urllib2.HTTPError:
    <whatever>


    but what I end up is catching any kind of HTTP error. I want to catch only if the specified webpage doesn't exist (404?).

    Continue reading...

Compartilhe esta Página