如何使用nordvpn服务器作为python请求的代理?
我试图使用nordvpn为python请求创建一个代理列表,但我似乎无法找到将服务器作为代理写入的正确格式 据我所知,以该服务器为例,其格式是这样的:如何使用nordvpn服务器作为python请求的代理?,python,proxy,python-requests,vpn,openvpn,Python,Proxy,Python Requests,Vpn,Openvpn,我试图使用nordvpn为python请求创建一个代理列表,但我似乎无法找到将服务器作为代理写入的正确格式 据我所知,以该服务器为例,其格式是这样的: proxy = { 'http': "username:password@us6181.nordvpn.com", 'https': "username:password@us6181.nordvpn.com" } 我尝试过各种组合: 我的登录电子邮件和密码 我的虚拟专用网帐户用户名和密码
proxy = {
'http': "username:password@us6181.nordvpn.com",
'https': "username:password@us6181.nordvpn.com"
}
我尝试过各种组合:
这些尝试都没有成功,我真的希望有人能告诉我正确的方法。以下是我制作的一个简单脚本:
import requests
from requests.auth import HTTPProxyAuth
import re
import random
#this is some proxy to use for nordvpn
#196.240.57.107
#37.120.217.219
up1 = ['username:password'
]
up2 = random.choice(up1)
u1 = re.findall(r'[\w]+:', up2)
p1 = re.findall(r':+[\w]+[\w]', up2)
u2 = str(u1)
u3 = u2.replace(':', '')
u3 = u3.replace('[', '')
u3 = u3.replace("'", '')
u3 = u3.replace(']', '')
p2 = str(p1)
p3 = p2.replace(':', '')
p3 = p3.replace('[', '')
p3 = p3.replace("'", '')
p3 = p3.replace(']', '')
proxies = {"http":"http://217.138.202.147"}
print(s)
auth = HTTPProxyAuth(u3, p3)
x = requests.get("http://ifconfig.me/ip")
print('Real ip: ' + x.text)
try:
r = requests.get("http://ipv4.icanhazip.com", proxies=proxies, auth=auth)
print(r.text)
except requests.exceptions.ProxyError:
proxies = {"https":"http://217.138.202.147"}
r = requests.get("http://ipv4.icanhazip.com/", proxies=proxies, auth=auth)
print(r.text)
有些代理不起作用,你必须测试它们
还有一个测试员
import requests
from requests.auth import HTTPProxyAuth
import re
import random
list1 = []
def main():
c1 = random.randint(0,230)
c2 = str(c1)
c3 = c2.replace("'", '')
url = 'https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters={"country_id":' + c3 + '}'
headers = {
'accept': "application/json/",
'content-type': "application/json"
}
response = requests.request("GET", url, headers=headers)
rep1 = response.text
rep2 = re.findall(r'"ip":"[\d]+.[\d]+.[\d]+.[\d]+"', rep1)
rep3 = str(rep2)
if '[]' not in rep3:
rep4 = rep3.replace('"ip":"', '')
rep4 = rep4.replace("'", '')
rep4 = rep4.replace('"', '')
rep4 = rep4.replace(']', '')
rep4 = rep4.replace('[', '')
rep4 = rep4.replace(',', '')
rep5 = rep4.split()
for list2 in rep5:
list1.append(list2)
if '[]' in rep3:
main()
main()
for a in list1:
try:
prox = a
up1 = ['username:password'
]
up2 = random.choice(up1)
u1 = re.findall(r'[\w]+:', up2)
p1 = re.findall(r':+[\w]+[\w]', up2)
u2 = str(u1)
u3 = u2.replace(':', '')
u3 = u3.replace('[', '')
u3 = u3.replace("'", '')
u3 = u3.replace(']', '')
p2 = str(p1)
p3 = p2.replace(':', '')
p3 = p3.replace('[', '')
p3 = p3.replace("'", '')
p3 = p3.replace(']', '')
proxies = {"http":"http://" + prox}
auth = HTTPProxyAuth(u3, p3)
r = requests.get("http://ipv4.icanhazip.com", proxies=proxies, auth=auth)
if '<p>The following error was encountered while trying to retrieve the URL: <a' in r:
print(prox + ' Auth failed')
elif '<p>The following error was encountered while trying to retrieve the URL: <a' not in r:
print(prox + ' Good')
print('Your Ip: ' + r.text)
except requests.exceptions.ProxyError:
print(prox + ' Failed')
pass
导入请求
从requests.auth导入HTTPProxyAuth
进口稀土
随机输入
列表1=[]
def main():
c1=random.randint(0230)
c2=str(c1)
c3=c2。替换(“,”)
url='1〕https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters={“国家id”:“+c3+”}
标题={
“接受”:“应用程序/json/”,
“内容类型”:“应用程序/json”
}
response=requests.request(“GET”,url,headers=headers)
rep1=response.text
rep2=re.findall(r'的“ip”:“[\d]+.[\d]+.[\d]+.[\d]+”,rep1)
rep3=str(rep2)
如果“[]”不在rep3中:
rep4=rep3.替换(““ip”:“,”)
rep4=rep4。替换(“”,“”)
rep4=rep4.替换(“,”)
rep4=rep4.替换(']','')
rep4=rep4.替换('[','')
rep4=rep4.替换(',','')
rep5=rep4.split()
对于rep5中的列表2:
list1.append(list2)
如果rep3中的“[]”:
main()
main()
对于列表1中的列表:
尝试:
prox=a
up1=['username:password'
]
up2=随机选择(up1)
u1=re.findall(r'[\w]+:',up2)
p1=re.findall(r':+[\w]+[\w]',up2)
u2=str(u1)
u3=u2。替换(“:”,“)
u3=u3.替换('[','')
u3=u3。替换(“,”)
u3=u3。替换(']','')
p2=str(p1)
p3=p2。替换(“:”,“)
p3=p3.替换('[','')
p3=p3。替换(“”,“”)
p3=p3。替换(']','')
代理={“http”:“http://”+prox}
auth=HTTPProxyAuth(u3,p3)
r=请求。获取(“http://ipv4.icanhazip.com,代理=代理,身份验证=身份验证)
如果“在尝试检索URL时遇到以下错误: