Unable to use proxies inside my flask app

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)

Hi,

I’ve replied to the last topic you opened, but you didn’t get back to us.

Rather than code, please can you provide the issue you’re seeing, e.g. any logs, error messages, URLs, reproduction steps, screenshots, etc. to show the problem.

Alan

hi there , thanks for replying my issue is now fixed earlier it was saying unable to connect to proxy but now its working

["45.90.218.215:4444","{\n  \"origin\": \"45.90.218.215\"\n}\n"]

{'Date': 'Thu, 25 Apr 2024 14:14:00 GMT', 'Content-Type': 'application/json', 'Content-Length': '77', 'Connection': 'keep-alive', 'CF-Ray': '879eefc5dad71d72-ATL', 'CF-Cache-Status': 'DYNAMIC', 'Access-Control-Allow-Origin': '*', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'rndr-id': '6cx5f2f7-7a5b-4d74', 'x-render-origin-server': 'Werkzeug/3.0.2 Python/3.11.8', 'Server': 'cloudflare', 'alt-svc': 'h3=":443"; ma=86400'}```

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.