i want to use proxies for sending request to a url. but in render its not working it always gives unable to conncet to proxy but my proxy is working!! heres a sample of code
#note that the same code works locally
from flask import Flask, jsonify
import requests
app = Flask(__name__)
# Define proxy here
proxy = "http://ip:port"
@app.route('/send_request', methods=['GET'])
def send_request():
url = request.args.get('url')
if not url:
return jsonify({'error': 'URL parameter is missing'}), 400
try:
response = requests.get(url, proxies={'http': proxy, 'https': proxy})
if response.status_code == 200:
return jsonify({'data': response.text}), 200
else:
return jsonify({'error': f'Request failed with status code {response.status_code}'}), 500
except Exception as e:
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0',port=81, debug=False)