I have looked at some posts that suggests that to specify the port number with python request, just add it after the host as: 'google.com:443' for example (I want to make https requests port 443).
However, I am not confident what is the case if I am using requests.Session()
?
In this case, I specify an adapter (code benefited from this post)
myCiphers = "AES128-SHA" +":"+ "AES256-SHA"
class myAdapter(HTTPAdapter):
def init_poolmanager(self, *args, **kwargs):
context = create_urllib3_context(ciphers=myCiphers)
kwargs['ssl_context'] = context
return super(myAdapter, self).init_poolmanager(*args, **kwargs)
def proxy_manager_for(self, *args, **kwargs):
context = create_urllib3_context(ciphers=defaultCiphers)
kwargs['ssl_context'] = context
return super(myAdapter, self).proxy_manager_for(*args, **kwargs)
myhost = 'https://google.com:443'
s = requests.Session()
s.mount(myhost,myAdapter())
response = s.get(myhost,verify=False,timeout=1)
The code seems to work, but these libraries are a bit tricky and I am afraid that this way of specifying the post number is not correct when mounting a host to an adapter.
Can an experienced person confirm please that the above method of specifying the port number with HTTP adapter mounted to a request session, and when making get request is correct?