简体   繁体   中英

Proxies with Python Requests module

I tried to use proxy with requests library

import requests

proxies = {'https': 'http://xxx.xxx.xxx.xx:yyyy',
           'http': 'http://xx.xxx.xxx.xxx:yyyy'}

r = requests.get('https://www.instagram.com', proxies=proxies)

print(r.status_code)

and faced this problem:

requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.wikipedia.org', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000013CB6D8D610>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond')))

I researched many different sites and solutions to this problem but nothing helped. Then I started asking questions: "How does a proxy work", "How to choose a proxy?". For my project, I need several (maybe even several dozen different proxies), so buying was not my option. (I used public proxies, correct me, if it is possible to buy one proxy or vpn account, so that it is not one permanent proxy adress, but many different ones)

Also, in the process of searching for an answer, I was faced with a strange (in my opinion) reaction of the program to changing the source of the Internet on the computer. From router, public wi-fi and mobile internet got different error results. How is this possible?

You should try this

Your code

proxies = {'https': 'http://xxx.xxx.xxx.xx:yyyy',
'http': 'http://xx.xxx.xxx.xxx:yyyy'}

New (remove http and https preffix in proxies dict)

proxies = {'https': 'xxx.xxx.xxx.xx:yyyy',
           'http': 'xx.xxx.xxx.xxx:yyyy'}

I also had a similar error, generally that error occurs for HTTPS validation, you can try adding the parameter Verify = False

r = requests.get('https://www.instagram.com', proxies=proxies, Verify=False)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM