RockCoder23 commited on
Commit
cbca33d
·
verified ·
1 Parent(s): e340c17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
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, with no cache
19
  response = requests.get(target_url, headers={
20
  "Cache-Control": "no-cache",
21
- "Pragma": "no-cache"
 
22
  })
23
 
24
- return jsonify({
25
- "status_code": response.status_code,
26
- "content": response.text
27
- })
28
- except Exception as e:
29
- return jsonify({"error": str(e)}), 500
 
 
 
 
 
 
 
 
 
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