I have a simple flask application I am running through the gevent server.
app = Flask(__name__)
def console(cmd):
p = Popen(cmd, shell=True, stdout=PIPE)
while True:
data = p.stdout.read(512)
yield data
if not data:
break
if isinstance(p.returncode, int):
if p.returncode > 0:
# return code was non zero, an error?
print 'error:', p.returncode
break
@app.route('/mp3', methods=['POST'])
def generate_large_mp3():
video_url = "url.com"
title = 'hello'
mp3 = console('command')
return Response(stream_with_context(mp3), mimetype="audio/mpeg3",
headers={"Content-Disposition": 'attachment;filename="%s.mp3"' % filename})
if __name__ == '__main__':
http_server = WSGIServer(('', 5000), app)
http_server.serve_forever()
How would I be able to make it so when my my console function runs that it runs via a proxy to download the url instead of the ip of the server?
Answered it,
Needed to simply update the env variable in the Popen
env = dict(os.environ)
env['http_proxy'] = proxies[random.randrange(0, len(proxies))]
env['https_proxy'] = proxies[random.randrange(0, len(proxies))]