mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 08:31:08 -05:00
Add timeout to requests calls
This commit is contained in:
@@ -26,7 +26,7 @@ class TurnstileMixin:
|
|||||||
'remoteip': request.META.get('REMOTE_ADDR'),
|
'remoteip': request.META.get('REMOTE_ADDR'),
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.post(settings.TURNSTILE_VERIFY_URL, data=data)
|
response = requests.post(settings.TURNSTILE_VERIFY_URL, data=data, timeout=60)
|
||||||
result = response.json()
|
result = response.json()
|
||||||
|
|
||||||
if not result.get('success'):
|
if not result.get('success'):
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ def create_user_profile(sender, instance, created, **kwargs):
|
|||||||
|
|
||||||
if avatar_url:
|
if avatar_url:
|
||||||
try:
|
try:
|
||||||
response = requests.get(avatar_url)
|
response = requests.get(avatar_url, timeout=60)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
img_temp = NamedTemporaryFile(delete=True)
|
img_temp = NamedTemporaryFile(delete=True)
|
||||||
img_temp.write(response.content)
|
img_temp.write(response.content)
|
||||||
|
|||||||
@@ -146,8 +146,8 @@ class Command(BaseCommand):
|
|||||||
},
|
},
|
||||||
headers={
|
headers={
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
}
|
},
|
||||||
)
|
timeout=60)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
self.stdout.write(self.style.SUCCESS('✓ API endpoint test successful'))
|
self.stdout.write(self.style.SUCCESS('✓ API endpoint test successful'))
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class EmailService:
|
|||||||
f"{settings.FORWARD_EMAIL_BASE_URL}/v1/emails",
|
f"{settings.FORWARD_EMAIL_BASE_URL}/v1/emails",
|
||||||
json=data,
|
json=data,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
timeout=60)
|
||||||
|
|
||||||
# Debug output
|
# Debug output
|
||||||
print(f"Response Status: {response.status_code}")
|
print(f"Response Status: {response.status_code}")
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ class LocationSearchView(View):
|
|||||||
response = requests.get(
|
response = requests.get(
|
||||||
'https://nominatim.openstreetmap.org/search',
|
'https://nominatim.openstreetmap.org/search',
|
||||||
params=params,
|
params=params,
|
||||||
headers={'User-Agent': 'ThrillWiki/1.0'}
|
headers={'User-Agent': 'ThrillWiki/1.0'},
|
||||||
)
|
timeout=60)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
results = response.json()
|
results = response.json()
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
@@ -170,8 +170,8 @@ def reverse_geocode(request):
|
|||||||
'format': 'json',
|
'format': 'json',
|
||||||
'addressdetails': 1
|
'addressdetails': 1
|
||||||
},
|
},
|
||||||
headers={'User-Agent': 'ThrillWiki/1.0'}
|
headers={'User-Agent': 'ThrillWiki/1.0'},
|
||||||
)
|
timeout=60)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
result = response.json()
|
result = response.json()
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class Command(BaseCommand):
|
|||||||
try:
|
try:
|
||||||
# Download image
|
# Download image
|
||||||
self.stdout.write(f'Downloading from URL: {photo_url}')
|
self.stdout.write(f'Downloading from URL: {photo_url}')
|
||||||
response = requests.get(photo_url)
|
response = requests.get(photo_url, timeout=60)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
# Delete any existing photos for this park
|
# Delete any existing photos for this park
|
||||||
Photo.objects.filter(
|
Photo.objects.filter(
|
||||||
@@ -74,7 +74,7 @@ class Command(BaseCommand):
|
|||||||
try:
|
try:
|
||||||
# Download image
|
# Download image
|
||||||
self.stdout.write(f'Downloading from URL: {photo_url}')
|
self.stdout.write(f'Downloading from URL: {photo_url}')
|
||||||
response = requests.get(photo_url)
|
response = requests.get(photo_url, timeout=60)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
# Delete any existing photos for this ride
|
# Delete any existing photos for this ride
|
||||||
Photo.objects.filter(
|
Photo.objects.filter(
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
def download_image(self, url):
|
def download_image(self, url):
|
||||||
"""Download image from URL and return as Django File object"""
|
"""Download image from URL and return as Django File object"""
|
||||||
response = requests.get(url)
|
response = requests.get(url, timeout=60)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
img_temp = NamedTemporaryFile(delete=True)
|
img_temp = NamedTemporaryFile(delete=True)
|
||||||
img_temp.write(response.content)
|
img_temp.write(response.content)
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ def location_search(request: HttpRequest) -> JsonResponse:
|
|||||||
"limit": 10,
|
"limit": 10,
|
||||||
},
|
},
|
||||||
headers={"User-Agent": "ThrillWiki/1.0"},
|
headers={"User-Agent": "ThrillWiki/1.0"},
|
||||||
)
|
timeout=60)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
results = response.json()
|
results = response.json()
|
||||||
@@ -128,7 +128,7 @@ def reverse_geocode(request: HttpRequest) -> JsonResponse:
|
|||||||
"accept-language": "en",
|
"accept-language": "en",
|
||||||
},
|
},
|
||||||
headers={"User-Agent": "ThrillWiki/1.0"},
|
headers={"User-Agent": "ThrillWiki/1.0"},
|
||||||
)
|
timeout=60)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
result = response.json()
|
result = response.json()
|
||||||
|
|||||||
Reference in New Issue
Block a user