【发布时间】:2021-06-01 07:55:07
【问题描述】:
我们在 Compute Engine 中有许多用于抓取的 VM 实例,它们可能会在某些站点中被阻止,然后我们尝试使用 NordVPN 更改 IP。当我们检测到我们被阻止时,我们正在尝试创建一个 Python 脚本来自动更改 IP。目前,我们正在使用我们最近发现的这个 Python 包:NordVPN-switcher,但我们遇到了下一个错误:
Connecting you to Denver ...
An unknown error occurred while connecting to a different server!
An unknown error occurred while connecting to a different server! Retrying with a different server...
Traceback (most recent call last):
File "demo.py", line 13, in <module>
rotate_VPN(instructions) # refer to the instructions variable here
File "/home/eduardo_santos_housecallprosolut/.local/lib/python3.8/site-packages/nordvpn_switcher/nordvpn_switch.py", line 514, in rotate_VPN
raise Exception("Unable to connect to a new server. Please check your internet connection.\n")
Exception: Unable to connect to a new server. Please check your internet connection.
注意:我们有互联网连接。
VM 实例也安装了 NordVPN,如果我们手动尝试,我们可以更改它,但由于我们使用 SSH 连接到实例,在我们更改 IP 的那一刻,连接会丢失。
那么,目前的问题是:
- 如何正确动态更改实例的IP?
- 更改发生后如何保持连接。
注意:爬虫和所有逻辑都是docker化的,Python版本是3.9
正如我一开始提到的,我们有很多机器用于scrape,我们希望保留每个使用的IP的注册表以便更好地分配,可能使用Redis DB o MongoDB中的小型集合.你怎么看待这件事?有什么好的方法来开发这个?
非常感谢。
【问题讨论】:
-
你是如何连接到你的虚拟机的?嘘,当然,但是如何?你能粘贴你执行的命令来登录你的虚拟机吗?
-
我使用 GCP 网站进行连接(单击连接列中的 SSH 按钮)bul 还使用 gcloud 命令(在终端或 bash 脚本中):gcloud compute ssh --project=$project_name -- zone=us-west2-a $instance_name
标签: python networking google-cloud-platform google-compute-engine vpn