Spaces:
Build error
Build error
Download app.py from RockCoder23/GetProxyv2: direct link, hf CLI and curl.
- Browser
- Download file 1.74 kB
-
https://huggingface.co/spaces/RockCoder23/GetProxyv2/resolve/main/app.py
- Command line
-
hf download hf://spaces/RockCoder23/GetProxyv2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/RockCoder23/GetProxyv2/resolve/main/app.py
1.74 kB
| from flask import Flask, request, jsonify | |
| import requests | |
| app = Flask(__name__) | |
| def home(): | |
| return "Welcome to the Flask URL Fetcher!" | |
| def fetch_url_content(): | |
| data = request.json | |
| target_url = data.get('url') | |
| if not target_url: | |
| return jsonify({"error": "No URL provided"}), 400 | |
| try: | |
| # Make the GET request to the target URL (raw Pastebin link) | |
| response = requests.get(target_url, headers={ | |
| "Cache-Control": "no-cache", | |
| "Pragma": "no-cache", | |
| "Accept": "text/plain" # Ensure we get the raw plain text response | |
| }) | |
| if response.status_code == 200: | |
| return jsonify({ | |
| "status_code": response.status_code, | |
| "content": response.text # Raw content from Pastebin | |
| }) | |
| else: | |
| # Return detailed error info if status code is not 200 | |
| return jsonify({ | |
| "error": "Failed to fetch content", | |
| "status_code": response.status_code, | |
| "response_text": response.text | |
| }), 500 | |
| except requests.exceptions.RequestException as e: | |
| # Capture and log any exception that occurs during the request | |
| return jsonify({"error": f"Request failed: {str(e)}"}), 500 | |
| # Prevent caching for responses from this Flask app itself | |
| def add_no_cache_headers(response): | |
| response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0" | |
| response.headers["Pragma"] = "no-cache" | |
| response.headers["Expires"] = "-1" | |
| return response | |
| if __name__ == "__main__": | |
| app.run(host='0.0.0.0', port=7860) | |