8

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.

| improve this question | |
  • 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 1 '16 at 13:49
  • No, that did not work. I think the answer below is the right way to do it – user7157075 Dec 24 '19 at 9:43
4

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.
| improve this answer | |
  • 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 2 '16 at 9:35
  • 1
    @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 9 '16 at 0:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.