Python requests exception handling

后端 未结 5 1950
梦谈多话
梦谈多话 2020-12-25 09:43

How to handle exceptions with python library requests? For example how to check is PC connected to internet?

When I try

try:
    requests.get(\'http         


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-25 10:27

    for clarity, that is

    except requests.ConnectionError:
    

    NOT

    import requests.ConnectionError
    

     

    You can also catch a general exception (although this isn't recommended) with

    except Exception:
    

提交回复
热议问题