python - Django - how to make requests with proxies? -


i following guide: https://ultimatedjango.com/blog/how-to-consume-rest-apis-with-django-python-reques/

i wondering how make these requests using proxies? thinking part should modified:

def save_embed(request):      if request.method == "post":         form = submitembed(request.post)         if form.is_valid():             url = form.cleaned_data['url']             r = requests.get('http://api.embed.ly/1/oembed?key=' + settings.embedly_key + '&url=' + url) 

is there easier way ? use same proxy every time same api key. (2-3 api keys) cheers

you can pass "proxies" argument request.get method containing dictionary of proxy servers use different protocols, code becomes.

def save_embed(request):     if request.method == "post":         form = submitembed(request.post)         if form.is_valid():             url = form.cleaned_data['url']             proxies = {                 "http": "http://123.123.123.123:1234",                 "https": "https://123.123.123.123:1234",             }             r = requests.get('http://api.embed.ly/1/oembed?key=' + settings.embedly_key + '&url=' + url, proxies=proxies) 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -