Spaces:
Runtime error
Runtime error
| from flask import Flask, request, jsonify | |
| import requests | |
| app = Flask(__name__) | |
| def proxy(): | |
| url = request.json.get('url') | |
| headers = request.json.get('headers') | |
| data = request.json.get('data') | |
| print(f"URL: {url}") | |
| print(f"Headers: {headers}") | |
| print(f"Data: {data}") | |
| try: | |
| response = requests.post(url, headers=headers, json=data) | |
| response.raise_for_status() | |
| return jsonify(response.json()) | |
| except requests.exceptions.HTTPError as errh: | |
| print ("Http Error:", errh) | |
| return jsonify({"error": "HTTP error occurred", "details": str(errh)}), 500 | |
| except requests.exceptions.ConnectionError as errc: | |
| print ("Error Connecting:", errc) | |
| return jsonify({"error": "Connection error occurred", "details": str(errc)}), 500 | |
| except requests.exceptions.Timeout as errt: | |
| print ("Timeout Error:", errt) | |
| return jsonify({"error": "Timeout error occurred", "details": str(errt)}), 500 | |
| except requests.exceptions.RequestException as err: | |
| print ("OOps: Something Else", err) | |
| return jsonify({"error": "An error occurred", "details": str(err)}), 500 | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=5000) |