Answer the question
In order to leave comments, you need to log in
Where can I get a proxy in the form of a string or a domain?
from goslate import Goslate
import urllib.request as urllib
from time import sleep
import random
proxies = ['212.6.9.145', '92.125.5.53', '37.1.49.188', '46.191.151.22', '31.131.214.91', ' 46.8.113.46']
firstWords = ['hello']
translatedWords = []
class File(object):
def __init__(self, filename):
self.filename = filename
def writeToFile(self, toWrite):
with open(self.filename, 'a') as f:
f.write(toWrite)
def readFromFile(self, listTO, mode=''):
for i in range(0, len(listTO)):
listTO.pop(i)
if mode.lower() == 'line':
with open(self.filename, 'r') as f:
for line in f:
listTO.append(line)
else:
with open(self.filename, 'r') as f:
print(f.read())
for i in range(0, len(firstWords)):
proxy_handler = urllib.ProxyHandler({"http" : "http://" + str(random.choice(proxies)) + ":8080"})
proxy_opener = urllib. build_opener(urllib.HTTPHandler(proxy_handler), urllib.HTTPSHandler(proxy_handler))
print(Goslate(opener=proxy_opener).translate(firstWords[i], 'ru')
File "f:/File Trash/translate/main.py ", line 34, in
TypeError: '>' not supported between instances of 'ProxyHandler' and 'int'
I suspect that the digital value of the proxy is to blame, that is, in this line (proxy_handler = urllib.ProxyHandler({"http" : "http://" + str(random.choice(proxies)) + ":8080"}) ) a proxy is selected from the list, which contains, as it were, a numerical value, plus the documentation is given in the format proxy_handler = urllib2.ProxyHandler({"http" : " proxy-domain.name:8080 "}).
It all started with the fact that I had to write all this to a file, and without using a proxy, I got a Too Many Requests error.
So that's where to get the proxy in the format shown in the documentation.
Documentation link - https://pypi.org/project/goslate/
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question