Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument error on connect: int too long to convert #758

swohlerLL opened this issue May 31, 2016 · 10 comments

Argument error on connect: int too long to convert #758

swohlerLL opened this issue May 31, 2016 · 10 comments


Copy link

Attempting to perform a simple connection with IP address on local network, username and password yields the following error:
ArgumentError: argument 2: <class 'OverflowError'>: int too long to convert

I'm running this in the iPython interpreter, on a 64-bit machine with Anaconda as the base python environment:

Python 3.5.1 |Anaconda 2.5.0 (64-bit)| (default, Jan 29 2016, 15:01:46) [MSC v.1900 64 bit (AMD64)]
IPython 4.0.3 -- An enhanced Interactive Python.

The sequence of commands:

ssh = paramiko.SSHClient()
ssh.connect(host, username=username, password=password)

The full stack trace (some identifying info commented out with ***):

C:\Users\***\Anaconda3\lib\site-packages\paramiko\ in connect(self, hostname, port, username, password, pkey, key_filename, timeout, allow_agent, look_for_keys, compress, sock, gss_auth, gss_kex, gss_deleg_creds, gss_host, banner_timeout)
    378             gss_host = hostname
    379         self._auth(username, password, pkey, key_filenames, allow_agent,
--> 380                    look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
    382     def close(self):

C:\Users\***\Anaconda3\lib\site-packages\paramiko\ in _auth(self, username, password, pkey, key_filenames, allow_agent, look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
    528         if not two_factor and allow_agent:
    529             if self._agent is None:
--> 530                 self._agent = Agent()
    532             for key in self._agent.get_keys():

C:\Users\***\Anaconda3\lib\site-packages\paramiko\ in __init__(self)
    361             # no agent support
    362             return
--> 363         self._connect(conn)
    365     def close(self):

C:\Users\***\Anaconda3\lib\site-packages\paramiko\ in _connect(self, conn)
     64     def _connect(self, conn):
     65         self._conn = conn
---> 66         ptype, result = self._send_message(cSSH2_AGENTC_REQUEST_IDENTITIES)
     67         if ptype != SSH2_AGENT_IDENTITIES_ANSWER:
     68             raise SSHException('could not get keys from ssh-agent')

C:\Users\***\Anaconda3\lib\site-packages\paramiko\ in _send_message(self, msg)
     81     def _send_message(self, msg):
     82         msg = asbytes(msg)
---> 83         self._conn.send(struct.pack('>I', len(msg)) + msg)
     84         l = self._read_all(4)
     85         msg = Message(self._read_all(struct.unpack('>I', l)[0]))

C:\Users\***\Anaconda3\lib\site-packages\paramiko\ in send(self, data)
    122     def send(self, data):
--> 123         self._response = _query_pageant(data)
    125     def recv(self, n):

C:\Users\***\Anaconda3\lib\site-packages\paramiko\ in _query_pageant(msg)
     88     pymap = _winapi.MemoryMap(map_name, _AGENT_MAX_MSGLEN,
---> 89         _winapi.get_security_attributes_for_user(),
     90         )
     91     with pymap:

C:\Users\***\Anaconda3\lib\site-packages\paramiko\ in get_security_attributes_for_user(user)
    363     ctypes.windll.advapi32.SetSecurityDescriptorOwner(ctypes.byref(SD),
--> 364         user.SID, 0)
    365     return SA

ArgumentError: argument 2: <class 'OverflowError'>: int too long to convert
Copy link

birm commented Jun 4, 2016

I think that this is related to the confusing int sizes on x86-64 windows and advapi32.dll.

birm added a commit to birm/paramiko that referenced this issue Jun 4, 2016
force user SID to be cast as longlong, brought up in paramiko#758
Copy link

Most/all of the code in actually comes from @jaraco's Windows module (, so it may be more appropriate to apply the fix there (assuming he agrees it's appropriate) and then we can upgrade our vendored copy.

Copy link

This issue has resurfaced for me, I cannot open an ssh connection to anywhere with paramiko right now. I'm using an Anaconda 2.4.1 64-bit installation of Python 3.5.1, with paramiko 2.0.1. Tried updating paramiko, but I couldn't find a newer version.

Also, the issue is really strange, because until today, everything worked fine for me. I haven't changed anything, no windows reinstall, no python reinstall, nothing. Could have a silent windows update cause it?

Copy link

jaraco commented Jul 21, 2016

The issue has been corrected upstream (though it's quite possible there are other, related, failures that the test suite doesn't yet cover. The next step will be to re-vendor these changes into paramiko and test them. Would someone be wiling to do that?

Copy link

@jaraco How can I help? What should I do?

Copy link

jaraco commented Jul 21, 2016

Awesome. Thanks for offering to help @miso-belica.

The module in paramiko is just copy-pasta from the distribution. To update the repo, check out that project and then walk through and everyplace you see


or similar, replace the content with the contents from that module in You'll want to disregard imports... and there may be other aspects that you can disregard. It's been a while since I've last done it.

With any luck, when you're done, the diff on the should look very similar to this diff.

@bitprophet bitprophet added this to the 1.16.3 et al milestone Jul 21, 2016
Copy link

@jaraco I ended with this diff

diff --git a/paramiko/ b/paramiko/
index 77e0129..94bf601 100644
--- a/paramiko/
+++ b/paramiko/
@@ -118,6 +118,18 @@ CreateFileMapping.restype = ctypes.wintypes.HANDLE
 MapViewOfFile = ctypes.windll.kernel32.MapViewOfFile
 MapViewOfFile.restype = ctypes.wintypes.HANDLE

+UnmapViewOfFile = ctypes.windll.kernel32.UnmapViewOfFile
+UnmapViewOfFile.argtypes = ctypes.wintypes.HANDLE,
+RtlMoveMemory = ctypes.windll.kernel32.RtlMoveMemory
+RtlMoveMemory.argtypes = (
+    ctypes.c_void_p,
+    ctypes.c_void_p,
+    ctypes.c_size_t,
+ctypes.windll.kernel32.LocalFree.argtypes = ctypes.wintypes.HLOCAL,

@@ -307,6 +319,13 @@ class SECURITY_ATTRIBUTES(ctypes.Structure):
         self._descriptor = value
         self.lpSecurityDescriptor = ctypes.addressof(value)

+ctypes.windll.advapi32.SetSecurityDescriptorOwner.argtypes = (
+    ctypes.c_void_p,
+    ctypes.wintypes.BOOL,

And works like a charm 🙌 Is it possible to release new version of paramiko with this? This annoys me very long time :( Thanks for all your work.

Copy link

jaraco commented Jul 22, 2016

Looks good to me. I'll apply that and submit a PR. Thanks for testing.

Copy link

bk8190 commented Jul 25, 2016

That diff also worked for me

Copy link

Merged PR, this will be out in next bugfix release (today).

dkhapun pushed a commit to cyberx-labs/paramiko that referenced this issue Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

7 participants