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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

for the specific situation, I've tried 'head' before.. it returns 200 for 403 status codes, for some reason.
0

fast:

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

ref:python requests is slow

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.