简体   繁体   中英

Replicating “--connect-to” from curl in Python

From the command line, I am able to successfully execute a command as follows:

curl --cacert <cacert> --cert <cert> --connect-to ::1.2.3.4: https://some-identity.com:443/endpoint

I am doing this so the request ends up going to the 1.2.3.4 address (from the routing perspective), but all of the SSL handshake occurs using the some-identity.com address. I have to do this because unfortunately, the SSL certificates in use are being signed using the some-identity.com address, but the private IP of the server is 1.2.3.4 .

I am trying to use either aiohttp (preferably), or requests , but I cannot find the respective utilities to do this.

In aiohttp , I see that I can pass in an SSLContext (in the ssl package) object, but unfortunately, I can't seem to find any property within an SSLContext object that can be set dynamically.

For the requests library, it doesn't seem to have an option for me to override/change the host as I did using curl .

Is there another way to go about this through Python libraries? The last ditch option would be to simply use the curl command itself through Python, but that is not preferred.

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