python 请求冻结程序

python requests freeze program

我尝试使用请求从网页获取状态代码,但没有输出,程序停止在 request.get

我的代码

if requests.get("https://storage.googleapis.com/linear-theater-254209.appspot.com/v5.4animu.me/Hunter-x-Hunter/Hunter-x-Hunter-Episode-1-1080p.mp4").status_code == 200:
  print("link is working")
else:
  print("link is not working")

代码在另一台机器上运行

我认为它正在下载视频,但我只想要状态码

我之前没有使用请求下载文件,所以我知道这个

编辑: 它也适用于 Collaboratory https://colab.research.google.com/drive/1yECaNKQNsyDUuGhBfcEa2OhDUUqqeg_q

您可以使用 requests.head() 来获得 headers,如下所示:

    import requests

    if requests.head("https://storage.googleapis.com/linear-theater-254209.appspot.com/v5.4animu.me/Hunter-x-Hunter/Hunter-x-Hunter-Episode-1-1080p.mp4").status_code == 200:
      print("link is working")
    else:
      print("link is not working")

requests.get() 将下载请求的 URL,由于您在此处请求的文件不小,因此可能需要一些时间。如果你想检查 headers 和状态代码,最好使用 requests.head() 代替。