12

I have to following problem. I need to check if certain urls are working and returning a correct response. I want to use python requests for this. However the urls have a redirect in it if the device or geo is incorrect and we need to check a lot of urls for mobile sites and multiple geo's.

Is there a way to work through a VPN with Python requests?

Edit: I forgot to mention, this is for a ubuntu 14.04 server. So not a home pc. On my laptop I use HideMyAss and IpVanish but I want to run a cron job on my server to check it automatically. I don't need to hide any information so I can use a proxy as well.

user3605780
  • 6,542
  • 13
  • 42
  • 67
  • 4
    Can't you just setup the VPN on your computer so that all your connections go through the VPN? This way your Python requests will also go through the VPN. – Patrick Kostjens Feb 01 '16 at 13:49
  • No, that did not work. I think the answer below is the right way to do it –  Dec 24 '19 at 09:43

1 Answers1

9

Depending on the OS you use, these options are available:

  1. If OS X: use the Apple's Automator scripts to switch VPN connections (provided they are set up beforehand). You can use then a bash script which will wrap your python script and switch connections (based on URL, for example)
  2. Use a list of proxies (not VPNs). This is the easiest solution
  3. Use a custom VPN connection management, something like this: https://gist.github.com/domenkozar/1547663 This option will require a lot of work though.
Igor
  • 2,834
  • 2
  • 26
  • 44
  • 1
    Thanks for pointing me to proxies instead of VPNs. This is indeed an option. However I don't find so many working http proxies and sock4/5 doesn't seem to be working. Is there a way to get sock4/5 working with requests? – user3605780 Feb 02 '16 at 09:35
  • 2
    @user3605780 You can, but you have to update to latest version: `2.10.0`. Previous versions only accept http and https proxies. – Nuno André Jul 09 '16 at 00:03