Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3718,7 +3718,15 @@ async def send_product_image_with_caption(from_number: str, product: Dict[str, A
|
|
3718 |
# Test the image URL first
|
3719 |
try:
|
3720 |
logger.info(f"[Product] Testing image URL accessibility: {image_url}")
|
3721 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3722 |
if test_response.status_code != 200:
|
3723 |
logger.warning(f"[Product] Image URL not accessible (status {test_response.status_code}): {image_url}")
|
3724 |
raise Exception(f"Image URL not accessible: {test_response.status_code}")
|
@@ -4015,6 +4023,50 @@ async def test_whatsjet_payloads(phone: str):
|
|
4015 |
"results": results
|
4016 |
}
|
4017 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4018 |
if __name__ == "__main__":
|
4019 |
# Launch FastAPI app
|
4020 |
import uvicorn
|
|
|
3718 |
# Test the image URL first
|
3719 |
try:
|
3720 |
logger.info(f"[Product] Testing image URL accessibility: {image_url}")
|
3721 |
+
headers = {
|
3722 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
3723 |
+
'Accept': 'image/webp,image/apng,image/*,*/*;q=0.8',
|
3724 |
+
'Accept-Language': 'en-US,en;q=0.9',
|
3725 |
+
'Accept-Encoding': 'gzip, deflate, br',
|
3726 |
+
'Connection': 'keep-alive',
|
3727 |
+
'Upgrade-Insecure-Requests': '1'
|
3728 |
+
}
|
3729 |
+
test_response = requests.head(image_url, headers=headers, timeout=10, allow_redirects=True)
|
3730 |
if test_response.status_code != 200:
|
3731 |
logger.warning(f"[Product] Image URL not accessible (status {test_response.status_code}): {image_url}")
|
3732 |
raise Exception(f"Image URL not accessible: {test_response.status_code}")
|
|
|
4023 |
"results": results
|
4024 |
}
|
4025 |
|
4026 |
+
@app.get("/test-cpanel-image-access")
|
4027 |
+
async def test_cpanel_image_access():
|
4028 |
+
"""
|
4029 |
+
Test endpoint to check if cPanel image URLs are now accessible with browser-like headers.
|
4030 |
+
"""
|
4031 |
+
try:
|
4032 |
+
image_url = "https://amgocus.com/uploads/images/Respira%20Aid%20Plus.jpg"
|
4033 |
+
|
4034 |
+
# Test with browser-like headers
|
4035 |
+
headers = {
|
4036 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
4037 |
+
'Accept': 'image/webp,image/apng,image/*,*/*;q=0.8',
|
4038 |
+
'Accept-Language': 'en-US,en;q=0.9',
|
4039 |
+
'Accept-Encoding': 'gzip, deflate, br',
|
4040 |
+
'Connection': 'keep-alive',
|
4041 |
+
'Upgrade-Insecure-Requests': '1'
|
4042 |
+
}
|
4043 |
+
|
4044 |
+
logger.info(f"[Test] Testing cPanel image URL with browser headers: {image_url}")
|
4045 |
+
response = requests.head(image_url, headers=headers, timeout=10, allow_redirects=True)
|
4046 |
+
|
4047 |
+
result = {
|
4048 |
+
"image_url": image_url,
|
4049 |
+
"status_code": response.status_code,
|
4050 |
+
"headers": dict(response.headers),
|
4051 |
+
"accessible": response.status_code == 200,
|
4052 |
+
"timestamp": datetime.now().isoformat()
|
4053 |
+
}
|
4054 |
+
|
4055 |
+
if response.status_code == 200:
|
4056 |
+
logger.info(f"[Test] ✅ cPanel image URL is now accessible!")
|
4057 |
+
else:
|
4058 |
+
logger.warning(f"[Test] ❌ cPanel image URL still not accessible (status {response.status_code})")
|
4059 |
+
|
4060 |
+
return result
|
4061 |
+
|
4062 |
+
except Exception as e:
|
4063 |
+
logger.error(f"[Test] Error testing cPanel image access: {e}")
|
4064 |
+
return {
|
4065 |
+
"error": str(e),
|
4066 |
+
"image_url": image_url,
|
4067 |
+
"timestamp": datetime.now().isoformat()
|
4068 |
+
}
|
4069 |
+
|
4070 |
if __name__ == "__main__":
|
4071 |
# Launch FastAPI app
|
4072 |
import uvicorn
|