Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,18 +15,28 @@ def fetch_url_content():
|
|
| 15 |
return jsonify({"error": "No URL provided"}), 400
|
| 16 |
|
| 17 |
try:
|
| 18 |
-
# Make the GET request to the target URL
|
| 19 |
response = requests.get(target_url, headers={
|
| 20 |
"Cache-Control": "no-cache",
|
| 21 |
-
"Pragma": "no-cache"
|
|
|
|
| 22 |
})
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Prevent caching for responses from this Flask app itself
|
| 32 |
@app.after_request
|
|
|
|
| 15 |
return jsonify({"error": "No URL provided"}), 400
|
| 16 |
|
| 17 |
try:
|
| 18 |
+
# Make the GET request to the target URL (raw Pastebin link)
|
| 19 |
response = requests.get(target_url, headers={
|
| 20 |
"Cache-Control": "no-cache",
|
| 21 |
+
"Pragma": "no-cache",
|
| 22 |
+
"Accept": "text/plain" # Ensure we get the raw plain text response
|
| 23 |
})
|
| 24 |
|
| 25 |
+
if response.status_code == 200:
|
| 26 |
+
return jsonify({
|
| 27 |
+
"status_code": response.status_code,
|
| 28 |
+
"content": response.text # Raw content from Pastebin
|
| 29 |
+
})
|
| 30 |
+
else:
|
| 31 |
+
# Return detailed error info if status code is not 200
|
| 32 |
+
return jsonify({
|
| 33 |
+
"error": "Failed to fetch content",
|
| 34 |
+
"status_code": response.status_code,
|
| 35 |
+
"response_text": response.text
|
| 36 |
+
}), 500
|
| 37 |
+
except requests.exceptions.RequestException as e:
|
| 38 |
+
# Capture and log any exception that occurs during the request
|
| 39 |
+
return jsonify({"error": f"Request failed: {str(e)}"}), 500
|
| 40 |
|
| 41 |
# Prevent caching for responses from this Flask app itself
|
| 42 |
@app.after_request
|