vendredi 6 septembre 2019

How do i detect a http error 500 with requests?

I took a look at this post, only changing a 503 error to a 500 error, but i am not able to detect it at all. I want to generate a random lowercase 6-digit Base36 number, and want to use it as a reddit post ID to find a truly random reddit post from a specific subreddit:

import random
import string
import requests



x = ''.join(random.choices(string.ascii_lowercase + string.digits, k=6))
s = requests.Session()
response = s.get("https://www.reddit.com/r/funny/comments/"+x)
print("https://www.reddit.com/r/funny/comments/"+x)

if response.status_code == 500:
    print("test")

But i do not get anything back. Is it because 500 errors cant be caught? Or is it a problem thats specific to the site im trying to reach?




Aucun commentaire:

Enregistrer un commentaire