mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
add timeouts to all HTTP requests to avoid hangs
This commit is contained in:
parent
da69a87978
commit
1a2203038c
2 changed files with 4 additions and 3 deletions
|
@ -83,7 +83,7 @@ class Recaptcha3Validator(object):
|
|||
'response': response
|
||||
}
|
||||
|
||||
http_response = requests.post(RECAPTCHA_VERIFY_SERVER, data)
|
||||
http_response = requests.post(RECAPTCHA_VERIFY_SERVER, data, timeout=10)
|
||||
if http_response.status_code != 200:
|
||||
return False
|
||||
|
||||
|
|
|
@ -204,7 +204,7 @@ def is_video_url(url):
|
|||
def mime_type_using_head(url):
|
||||
# Find the mime type of a url by doing a HEAD request - this is the same as GET except only the HTTP headers are transferred
|
||||
try:
|
||||
response = requests.head(url)
|
||||
response = requests.head(url, timeout=5)
|
||||
response.raise_for_status() # Raise an exception for HTTP errors
|
||||
content_type = response.headers.get('Content-Type')
|
||||
if content_type:
|
||||
|
@ -1053,7 +1053,8 @@ def in_sorted_list(arr, target):
|
|||
# Makes a still image from a video url, without downloading the whole video file
|
||||
def generate_image_from_video_url(video_url, output_path, length=2):
|
||||
|
||||
response = requests.get(video_url, stream=True, headers={'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0'}) # Imgur requires a user agent
|
||||
response = requests.get(video_url, stream=True, timeout=5,
|
||||
headers={'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0'}) # Imgur requires a user agent
|
||||
content_type = response.headers.get('Content-Type')
|
||||
if content_type:
|
||||
if 'video/mp4' in content_type:
|
||||
|
|
Loading…
Add table
Reference in a new issue