I am writing some python client code and, due to some environmental constraints, I want to specify a URL and also control how it is resolved. I can accomplish this with curl by using the --resolve flag. Is there a way to do something similar with Python's requests library?
Ideally this would work in Python 2.7 but I can make a 3.x solution work as well.
Late answer, but there's a module called forcediphttpsadapter that does exactly this:
pip3 install forcediphttpsadapter
import requests
from forcediphttpsadapter.adapters import ForcedIPHTTPSAdapter
url = 'https://domain.tld/path'
session = requests.Session()
session.mount(url, ForcedIPHTTPSAdapter(dest_ip='x.x.x.x')) # type the desired ip
r = session.get(url, verify=False)
print(r.text)
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With