T
T
TemaKam2021-01-15 14:09:53
Python
TemaKam, 2021-01-15 14:09:53

Why don't proxies work in the program on a virtual machine?

They work on my machine, on a virtual machine I get errors:

'Cannot connect to proxy.', timeout('_ssl.c:1106: The handshake operation timed out')

The code I use is clear, the same:
# чек прокси
    def check_proxy(self, proxies, headers):
        global timeout
        proxies = dict(https=proxies)
        # url = 'https://api.ipify.org/'
        url = 'https://api.vk.com/method/search.getHints'
        params = dict(v=self.version)
        try:
            if headers != '':
                res = requests.get(url, params, proxies=proxies, timeout=timeout, headers=headers)
            else:
                res = requests.get(url, params, proxies=proxies, timeout=timeout)
        except Exception as e:
            if 'Max retries' not in str(e) or 'Cannot connect to proxy' in str(e):
                with open('error\ошибки с прокси.txt', mode='a', encoding='utf-8') as file:
                    file.write(str(datetime.today()) + '\n' + str(proxies) + '\n' + str(e) + '\n' + '\n')
                return False
        return True

Is this a virtual machine problem? If yes, how to decide?

Increasing the timeout does not help

I tried it in the browser - it connects to the proxy there normally
PS I know about global variables, I'll fix it

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question