AttributeError: 'module' object has no attribute 'c_ssize_t' #802

Closed
X286 opened this Issue Aug 24, 2016 · 12 comments

Projects

None yet

3 participants

@X286
X286 commented Aug 24, 2016 edited

import paramiko

ip=
port=22
username='username'
password='passw'

cmd='dir'

ssh=paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.WarningPolicy())
ssh.connect(ip,port, username,password, look_for_keys=False)

stdin,stdout,stderr=ssh.exec_command(cmd)
outlines=stdout.readlines()
resp=''.join(outlines)
print(resp)

gives me error:

C:\Python27\lib\site-packages\paramiko\client.py:664: UserWarning: Unknown ssh-rsa host key for <host>: <key>
  (key.get_name(), hostname, hexlify(key.get_fingerprint())))
Traceback (most recent call last):
  File "sshclient.py", line 13, in <module>
    ssh.connect(ip,port, username,password)
  File "C:\Python27\lib\site-packages\paramiko\client.py", line 380, in connect
    look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
  File "C:\Python27\lib\site-packages\paramiko\client.py", line 536, in _auth
    self._agent = Agent()
  File "C:\Python27\lib\site-packages\paramiko\agent.py", line 355, in __init__
    from . import win_pageant
  File "C:\Python27\lib\site-packages\paramiko\win_pageant.py", line 36, in <module>
    from . import _winapi
  File "C:\Python27\lib\site-packages\paramiko\_winapi.py", line 92, in <module>
    GlobalAlloc.argtypes = ctypes.wintypes.UINT, ctypes.c_ssize_t
AttributeError: 'module' object has no attribute 'c_ssize_t'

OS: Win7

@bitprophet
Member

This should have been fixed a while ago in #619 (Paramiko 1.15.5, 1.16.1, and up). Please comment w/ your specific paramiko version if you're on something newer than those and still seeing this. thanks!

@bitprophet bitprophet closed this Aug 25, 2016
@X286
X286 commented Aug 26, 2016

Hello! my version 2.0.2. upgrade by using pip.
i connect to RPI (Rasbian), if it helps. on rpi installed openSSH. That's all.
Thanks for your answer.
ps Sorry, I only teach English.

@bitprophet
Member

Wonder if @jaraco sees anything I don't, here? All I can say is to make extra sure you don't have multiple Paramiko versions installed somehow (i.e. maybe you have an older one that is running instead of the 2.0.2 pip installed).

@jaraco
Contributor
jaraco commented Aug 27, 2016

@X286: The error you've reported looks like an issue with your Python installation. ctypes.c_ssize_t should be provided by the stdlib.

What do you get if you run python -c "import ctypes, sys; print(sys.version); ctypes.c_ssize_t"? If it crashes with the same error, I recommend upgrading or re-installing your Python.

@jaraco
Contributor
jaraco commented Aug 27, 2016

Okay. I digged a little deeper. Looking at the ctypes docs, c_ssize_t was added in Python 3.2, which means it was probably not backported to Python 2.7 until late.

More importantly, though, the GlobalAlloc API docs indicate that this parameter is meant to be a c_size_t and not c_ssize_t anyway, and since that's the only place in jaraco.windows that c_ssize_t is used, I'm guessing that's a typo and it'll work better and on more Pythons with c_size_t.

@jaraco jaraco referenced this issue in jaraco/jaraco.windows Aug 27, 2016
Closed

GlobalAlloc should use c_size_t for the argument #8

@X286
X286 commented Aug 27, 2016

@jaraco @bitprophet
Hello!
I try your solution in Monday.
On my home computer i cannot reproduce error.
Thanks for your support.

@X286
X286 commented Aug 29, 2016

@jaraco
Traceback (most recent call last):
File "E:/NFC_Operator/testssh.py", line 3, in
ctypes.c_ssize_t
AttributeError: 'module' object has no attribute 'c_ssize_t'
2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)]
yep,
code "import ctypes, sys; print(sys.version); ctypes.c_ssize_t"
gives me error too.
oh i read your fix.
Thank you.

@jaraco
Contributor
jaraco commented Aug 31, 2016

That's interesting that Python 2.7.12 is missing that attribute. I wonder if there's something new about that release that removed that attribute, perhaps by mistake.

@jaraco
Contributor
jaraco commented Aug 31, 2016

I just installed the latest Python (admittedly 64-bit version), and it has that attribute. I think there may be something corrupted in your installation.

C:\Users\jaraco> py -2
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> ctypes.c_ssize_t
<class 'ctypes.c_longlong'>
@jaraco
Contributor
jaraco commented Aug 31, 2016

32-bit version also has the attribute. I think we can confidently say that the issue is isolated to your installation.

C:\Users\jaraco> py -2.7-32
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> ctypes.c_ssize_t
<class 'ctypes.c_long'>
@X286
X286 commented Aug 31, 2016

@jaraco
Thank you.
I'm sorry to have spent your time .

@bitprophet
Member

Thanks for digging @jaraco !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment