title: How to force WinRM port to 5986 when creating a session with pywinrm python module using kerberos transport?
body: <p>I'm using <a href="https://github.com/diyan/pywinrm/tree/master/winrm" rel="nofollow noreferrer">pywinrm module</a> from RHEL successfully with Kerberos and WinRM HTTP listeners (TCP 5985) on target Windows machines.</p>
  <p>Now I'd like to get a rid of all HTTP (5985) listeners, keeping only HTTPs listener (5986) on all Windows hosts.</p>
  <p>The issue is that pywinrm module seems to <a href="https://github.com/diyan/pywinrm/blob/master/winrm/__init__.py" rel="nofollow noreferrer">automatically choose the remote WinRM port</a> for WinRM based on the transport (5986 for &quot;ssl&quot; transport, 5985 for all other transport methods).</p>
  <p><strong>Error with &quot;kerberos&quot; transport</strong></p>
  <blockquote>
  <pre><code>(ConnectTimeout, (MaxRetryError(&quot;HTTPConnectionPool(host='foo.tld', port=5985): Max retries exceeded with url: /wsman (Caused by ConnectTimeoutError
  </code></pre>
  </blockquote>
  <p>I can't find a way to pass the port number as an argument when creating the winrm session.</p>
  <p><strong>Code example</strong></p>
  <pre><code>import kerberos
  import winrm
  
  # Automatically picks 5985 for WinRM remote port
  session = winrm.Session(&quot;foo.tld&quot;, auth=(&quot;my_user@DOMAIN.TLD&quot;, ''), transport='kerberos', server_cert_validation='ignore')
  
  # Automatically picks 5985 for WinRM remote port
  session = winrm.Session(&quot;foo.tld&quot;, auth=(&quot;my_user@DOMAIN.TLD&quot;, 'Xxxxxxx'), transport='ssl', server_cert_validation='ignore')
  
  cmd = &quot;&quot;&quot;
  get-aduser -filter &quot;samaccountname -eq 'john'&quot;
  &quot;&quot;&quot;
  try:
      session.run_ps(cmd)
      if run_ps.status_code == 0:
          print(run_ps.std_out)
      else:
          print(run_ps.std_err)
  except Exception as e:
      print(&quot;WinRM Error: {}&quot;.format(e))
  </code></pre>
  <p>I'm confused because <a href="https://docs.ansible.com/ansible/latest/user_guide/windows_winrm.html#inventory-options" rel="nofollow noreferrer">Ansible</a>, that rely on this same pywinrm Python module has two settings for the same and it seems that HTTPs listener + Kerberos authentication might be supported:</p>
  <ul>
  <li>ansible_winrm_scheme (http or https)</li>
  <li>ansible_winrm_transport (authentication method)</li>
  </ul>
  <p>Is there a way to &quot;force&quot; pywinrm &quot;kerberos&quot; method with 5986 port (HTTPs listener) instead of 5985 or is 5985 port (HTTP listener) only available by design for &quot;kerberos&quot; transport?</p>