Python Requests doesnt work for https proxy

Mrs_HillaryClinTon

I try to use https proxy in python like this:

proxiesDict ={
  'http':  'http://' + proxy_line,
  'https': 'https://' + proxy_line
}


response = requests.get('https://api.ipify.org/?format=json', proxies=proxiesDict, allow_redirects=False)

proxy_line is a proxy read from file in the format of ip:port. I checked this https proxy in browser and it works. But in python this code hangs for a few seconds and then i get exception:

HTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: /?format=json (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0425E450>: Failed to establish a new connection: [WinError 10060] 

I tried to use socks5 proxy, and it works on socks5 proxies with a PySocks installed. But for https i get this exception, can someone help me

cs95

When specifying a proxy list for requests, the key is the protocol, and the value is the domain/ip. You don't need to specify http:// or https:// again, for the actual value.

So, your proxiesDict will be:

proxiesDict = {
  'http':  proxy_line,
  'https': proxy_line
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

check Python requests with charles proxy for HTTPS

updating PRAW requests HTTPS Proxy

How to make python Requests work via socks proxy

Python requests API using proxy for https request get 407 Proxy Authentication Required

Cant seem to get https and socks proxies to work using python requests

mathematical formula in python doesnt work

On HTTPS and Tomcat, GET requests work but not POST requests

Force cURL to use GET on proxy for HTTPs requests

Proxy for requests with grunt only works with HTTP (and not HTTPS)

Proxy http and https requests with one virtualhost in Apache

Unable to view HTTPS requests in Charles Proxy with Android

Python HTTPS Proxy Tunnelling

Python HTTPS requests (urllib2) to some sites fail on Ubuntu 12.04 without proxy

docker reverse-proxy doesnt work when change network (by --net)

NGINX simple proxy doesnt work, get 404 on location

Set up a proxy with python requests

Catch proxy errors on requests python

Python Proxy Requests and User Agent

requests to HTTPS work while requests to HTTP do not work

Python - Requests Library - How to ensure HTTPS requests

Python requests call fails with HTTPS

python requests and urllib https errors

Why python if command doesnt work correctly?

tkinter python - menu button doesnt work with a loop

Python function doesnt work inside a loop

the logic in my python program doesnt seem to work

The else branch in the if statement doesnt work properly (python)

My words filter doesnt work(Python, Aiogram)

Make request with HTTPS proxy in python