0

I'm trying to check if some file links are up or not. I've tried with requests library:

import requests
url = 'http://releases.libreelec.tv/LibreELEC-RPi2.arm-9.0.1.img.gz'
print(requests.get(url).status_code)

And also with httplib2:

import httplib2
url = 'http://releases.libreelec.tv/LibreELEC-RPi2.arm-9.0.1.img.gz'
http = httplib2.Http()
resp = http.request(url)[0]
print(resp.status)

As the link is good.. it takes too long (I've never waited it to finish) to return a '200' status code. It works fine for forbidden (403) code. The point is i need it to be fast.

Henno Brandsma
  • 2,116
  • 11
  • 12
Tiago Aquino
  • 35
  • 1
  • 10

2 Answers2

1

If you need to get response code only, you can use requests.head:

import requests
try:
    r = requests.head('http://releases.libreelec.tv/LibreELEC-RPi2.arm-9.0.1.img.gz')
    print(r.status_code)
except:
    print('problem')

As shown in this topic, it should be faster as it gets only head, however please check if it is fast enough for your purpose.

Daweo
  • 31,313
  • 3
  • 12
  • 25
0

fast:

r = requests.get(url, stream=True)

ref:python requests is slow

Vox
  • 506
  • 2
  • 13