[Python] Printing out errors with Requests library [duplicate]

Discussão em 'Python' iniciado por Stack, Maio 7, 2025.

  1. Stack

    Stack Membro Participativo

    http://www.mobify.com/blog/http-requests-are-hard/ discusses various types of errors which can be encountered with a request. The article focuses on catching each one. I would like to simply print out the error type whenever any error occurs. In the article, one example is:

    url = "http://www.definitivelydoesnotexist.com/"

    try:
    response = request.get(url)
    except requests.exceptions.ConnectionError as e:
    print "These aren't the domains we're looking for."


    Is there a way to rewrite the last 2 lines in pseudocode as:

    except requests.ANYERROR as e:
    print e

    Continue reading...

Compartilhe esta Página