use vpn with python requests

醉酒当歌 提交于 2019-12-29 08:02:16

问题


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.


回答1:


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.


来源:https://stackoverflow.com/questions/35132154/use-vpn-with-python-requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!