Proxy A GET Request To A Different Site In Python
I want to forward a GET request that I get from a client to a different site, In my case- A m3u8 playlist request to a streaming site to handle. Does anyone know how can it be done
Solution 1:
If you want to proxy, first install requests
:
pip install requests
then, get the file in the server and serve the content, ej:
import requests
from flask import Flask, Response
app = Flask(__name__)
@app.route('/somefile.m3u')
def proxy():
url = 'https://www.example.com/somefile.m3u'
r = requests.get(url)
return Response(r.content, mimetype="text/csv")
app.run()
If you just want to redirect, do this (requests
not needed):
from flask import Flask, redirect
app = Flask(__name__)
@app.route('/redir')
def redir():
url = 'https://www.example.com/somefile.m3u'
return redirect(url, code=302)
app.run()
Post a Comment for "Proxy A GET Request To A Different Site In Python"