I am using requests.get on a hostname, and wanna to get to know peer IP and port. I did google and found this could be done only when we set stream parameter as True. I am just curious, why stream as False cannot achieve this? Any design consideration? I found the link "https://requests.readthedocs.io/en/latest/user/advanced/#body-content-workflow" for stream, but not help here.
I played with code.
import requests
rsp = requests.get('https://xxx')
print rsp.status_code
print "rsp.raw type"
print type(rsp.raw)
print "_fp type "
print type(rsp.raw._fp)
print "_connection type"
print type(rsp.raw._connection)
print "_sock type"
print type(rsp.raw._connection.sock)
print rsp.raw._connection.sock.getpeername()
I found when stream is false, _connection is NoneType and exited. When stream is false, _connection type is "<class 'urllib3.connection.HTTPSConnection'>" and getpeername() returns {ip,port}