Python Requests lib - How to get IP address of connected host after getting the response?

37 Views Asked by At

I'm trying to understand how I could access information about host that the request connected to. I have situation when behind a hostname, there is a multiple IP addresses that you can connect to, so for example x.com can route me to 1.2.3.4 or 2.3.4.5. I need that information after receiving response from requests. I'm using python 3.10 if that matters.

My code is as follows:

retry_strategy = Retry(total=1,
backoff_factor=0.5,
status_forcelist=[400, 408, 429, 500, 501, 502, 503, 504],
raise_on_status=False)
        
self.adapter = HTTPAdapter(max_retries=retry_strategy)

# other, not important code

s = Session()
s.mount('https://', self.adapter)
response = s.get(url, headers=self.headers, stream=True, timeout=60)

Where (if anywhere?) should I look for that kind of information? I found something about response.raw but the connection there is declared as None.

0

There are 0 best solutions below