requests 模块的 get 方法中的代理似乎不起作用
我已经用谷歌搜索了代理的语法,它应该与我的代码中的相同,并且没有其他方法,但无论如何,在使用代理之后, https://api.ipify.org 仍然返回我自己的外部 IP 地址。
import requests
import random
def get_site():
http = ['85.26.146.169:80', '85.143.70.165:80', '213.135.118.150:3128']
proxi = {
'http': 'http://'+random.choice(http)
}
# proxi = {
# 'http': 'http://85.26.146.169:80'
# }
print(requests.get('https://api.ipify.org', proxies=proxi).text)
get_site()
带注释和未注释的变体都
不起作用将协议从 http 更改为 https 后,现在它可以正常工作,但我怀疑 18 个代理中的每一个都不起作用,而且我也可以轻松 ping 通它们。不过他们是免费的
import requests
import random
def get_site():
https = ['188.134.65.80:41890', '77.236.243.69:1256', '31.163.192.161:3129', '37.110.6.178:8080',
'31.131.67.14:8080', '77.238.129.14:55443', '85.235.184.186:3129', '195.133.71.199:8080',
'95.189.104.181:41890',
'78.36.198.158:80',
'188.246.186.142:41890',
'95.140.31.39:41890',
'178.74.103.46:8080',
'212.46.255.78:8080',
'195.68.187.222:3128',
'81.24.95.176:41258',
'89.22.152.32:53726',
'84.201.254.47:3128']
for i in range(len(https)):
proxi = {
'https': 'https://' + https[i]
}
print(requests.get('https://api.ipify.org', proxies=proxi).text)
I've googled the syntax for proxies and it should be the same as in my code and there is no other way around but anyways, after using proxies, https://api.ipify.org still returns my own external ip address.
import requests
import random
def get_site():
http = ['85.26.146.169:80', '85.143.70.165:80', '213.135.118.150:3128']
proxi = {
'http': 'http://'+random.choice(http)
}
# proxi = {
# 'http': 'http://85.26.146.169:80'
# }
print(requests.get('https://api.ipify.org', proxies=proxi).text)
get_site()
both commented and uncommented variants dont work
P.S. after changing protocol from http to https now it is working but I doubt that every single one from 18 proxies doesnt work and also i can easily ping them. they're free though
import requests
import random
def get_site():
https = ['188.134.65.80:41890', '77.236.243.69:1256', '31.163.192.161:3129', '37.110.6.178:8080',
'31.131.67.14:8080', '77.238.129.14:55443', '85.235.184.186:3129', '195.133.71.199:8080',
'95.189.104.181:41890',
'78.36.198.158:80',
'188.246.186.142:41890',
'95.140.31.39:41890',
'178.74.103.46:8080',
'212.46.255.78:8080',
'195.68.187.222:3128',
'81.24.95.176:41258',
'89.22.152.32:53726',
'84.201.254.47:3128']
for i in range(len(https)):
proxi = {
'https': 'https://' + https[i]
}
print(requests.get('https://api.ipify.org', proxies=proxi).text)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论