python - Proxies from a file with Requests -


how use proxies text file requests? proxies in file in format: ip:port can't build dict {'scheme' : 'scheme://ip:port'}

and need access 2 different sites same proxy , switch proxy. 1 of site uses http , other uses https.

i tried doing http request:

response = c.get(url, proxies = {'http': 'http://'+p}) 

and https request:

response = c.get(url, proxies = {'https': 'https://'+p}) 

but first 1 doesn't work , throws me error.

any workarounds this?

my assumption fails due untrusted ssl certificate.

requests.exceptions.sslerror: [errno 1] _ssl.c:503: error:14090086:ssl routines:ssl3_get_server_certificate:certificate verify failed

to solve this, read following post

however, if similar message this

connection server refused.

it can caused many reasons, such firewall blocking port or proxy configured badly. anyway, see if bug in program, try use proxy (ssl) in browser , surf internet.

regarding second question, shouldn't problem. instance, file proxies.txt has following data:

172.17.0.3:443 172.17.0.23:9443 172.17.0.34:80 

then, can infer scheme according port number. common ports end 443 https.

with open('proxies.txt', 'r') data     lines = data.readlines()  proxies = {'http': [], 'https': []} line in lines:     ip_port = line.split(':')     ip, port = (ip_port[0], ip_port[1]) if len(ip_port) > 1 else (ip_port[0], 80)     scheme = 'http'     if port.endswith('443'):         scheme = 'https'     proxies[scheme].append(join([scheme, '://', ip, ':', port])) 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -