我是python的新手,正在编写一些代码,并且我想使用Snapchat做一些测试。
但是当我运行下面的代码时,直到得到一个
"Index out of range"
很奇怪,因为索引从未超过列表长度120
那么我如何使我的代码通过代理连接?:
我的列表看起来像
[103.21.161.105:6667,
103.216.82.43:6667,
103.216.82.200:6667]
import sys
import os
import requests
import random
# pip install requests[socks]
name_of_file = sys.argv[0]
would_you_like_to_start = input("would you like to start (y/n)")
if would_you_like_to_start == "y" :
pass;
else:
print("Process Stopped")
quit()
dir_path = os.path.dirname(os.path.realpath(__file__))
print(dir_path)
#Connecting to a proxy with requests
print("Connecting to Proxy")
session = requests.session()
session.proxies = {}
ProxyNo = "No"
while ProxyNo == "No" :
i = random.randint(1,120)
proxie_list = open(dir_path + "/proxies.txt", 'r').readlines()
session.proxies['http'] = 'socks5h://' + proxie_list[i]
session.proxies['https'] = 'socks5h://' + proxie_list[i]
try:
r = session.get("http://httpbin.org/ip")
print(r.text)
ProxyNo = "Yes"
except :
ProxyNo = "No"