see this code
PROXY_HOST, PROXY_PORT = choice(proxies).rstrip().split(":")
fp = webdriver.FirefoxProfile()
# Direct = 0, Manual = 1, PAC = 2, AUTODETECT = 4, SYSTEM = 5
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http", PROXY_HOST)
fp.set_preference("network.proxy.http_port", PROXY_PORT)
fp.set_preference("network.proxy.ftp", PROXY_HOST)
fp.set_preference("network.proxy.ftp_port", PROXY_PORT)
fp.set_preference("network.proxy.ssl", PROXY_HOST)
fp.set_preference("network.proxy.ssl_port", PROXY_PORT)
proxies is a list of proxies in form 123.123.123.123:1234\n. The weird thing is, if i hardcode the two variables PROXY_HOST and PROXY_PORT it will use a proxy, if i try to read it from a file which i do like this
with open("proxies.txt") as f:
proxies = f.readlines()
the proxy settings are ignored. If i print the two vars, they are correct but not used.
So is there something I don’t see, how is it different to hardcode the ip and port or to read it from a file/list.
This is a how-do-I-properly-debug-issue. Look exactly at
proxiesin case this list is hardcoded vs.proxiesin case you read it from file. Best would be to print both varialbes usingrepr(). You’ll see a difference. The solution will be very simple: after reading the port from a file, it still is a string and needs to be converted to an integer. When you hardcode it, you define it as an integer in the first place.