Exception for password failure not clear

256 views
Skip to first unread message

will47

unread,
Jul 25, 2012, 1:24:47 PM7/25/12
to pysp...@googlegroups.com
If I connect using the wrong password, the exception I get is:
TypeError: super() argument 1 must be type, not classobj

Would it be possible to throw a more useful named exception that makes it clear that the login failed? This way, you can trap login failures (vs. some other kind of failure) with try / except more easily.

Seba

unread,
Jul 31, 2012, 9:32:07 AM7/31/12
to pysp...@googlegroups.com, wyar...@gmail.com
Hi,
  
    When providing wrong credentials you should be getting this error: 

pysphere.resources.vi_exception.VIApiException: [InvalidLoginFault]: Cannot complete login due to an incorrect user name or password.

InvalidLoginFault and the message after that are returned by the web service.

I haven't been able to get the error you sent. Can you provide more details on how to reproduce it? (a code snippet, your os and python version, etc)

Thanks!

Seba.

will47

unread,
Jul 31, 2012, 8:52:10 PM7/31/12
to pysp...@googlegroups.com
On Tuesday, July 31, 2012 6:32:07 AM UTC-7, Seba wrote:

    When providing wrong credentials you should be getting this error: 

pysphere.resources.vi_exception.VIApiException: [InvalidLoginFault]: Cannot complete login due to an incorrect user name or password.

InvalidLoginFault and the message after that are returned by the web service.

I haven't been able to get the error you sent. Can you provide more details on how to reproduce it? (a code snippet, your os and python version, etc)

This is using RHEL 5's stock Python 2.4. Here's a simple test case that shows the problem:

$ cat test_login.py
#!/usr/bin/python

import getpass
import os
import pysphere

host = "host.example.com"
user = os.getlogin()
password = getpass.getpass()
server = pysphere.VIServer()
server.connect(host, user, password)

server.disconnect()

$ ./test_login.py
Password:
Traceback (most recent call last):
  File "./test_login.py", line 11, in ?
    server.connect(host, user, password)
  File "/usr/lib/python2.4/site-packages/pysphere/vi_server.py", line 101, in connect
    raise VIApiException(e)
  File "/usr/lib/python2.4/site-packages/pysphere/resources/vi_exception.py", line 49, in __init__
    super(self.__class__, self).__init__(message, fault)

TypeError: super() argument 1 must be type, not classobj

$ python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /usr/lib64/python2.4/site.pyc matches /usr/lib64/python2.4/site.py
import site # precompiled from /usr/lib64/python2.4/site.pyc
# /usr/lib64/python2.4/os.pyc matches /usr/lib64/python2.4/os.py
import os # precompiled from /usr/lib64/python2.4/os.pyc
import posix # builtin
# /usr/lib64/python2.4/posixpath.pyc matches /usr/lib64/python2.4/posixpath.py
import posixpath # precompiled from /usr/lib64/python2.4/posixpath.pyc
# /usr/lib64/python2.4/stat.pyc matches /usr/lib64/python2.4/stat.py
import stat # precompiled from /usr/lib64/python2.4/stat.pyc
import errno # builtin
# /usr/lib64/python2.4/UserDict.pyc matches /usr/lib64/python2.4/UserDict.py
import UserDict # precompiled from /usr/lib64/python2.4/UserDict.pyc
# /usr/lib64/python2.4/copy_reg.pyc matches /usr/lib64/python2.4/copy_reg.py
import copy_reg # precompiled from /usr/lib64/python2.4/copy_reg.pyc
# /usr/lib64/python2.4/types.pyc matches /usr/lib64/python2.4/types.py
import types # precompiled from /usr/lib64/python2.4/types.pyc
import japanese # directory /usr/lib64/python2.4/site-packages/japanese
# /usr/lib64/python2.4/site-packages/japanese/__init__.pyc matches /usr/lib64/python2.4/site-packages/japanese/__init__.py
import japanese # precompiled from /usr/lib64/python2.4/site-packages/japanese/__init__.pyc
import japanese.aliases # directory /usr/lib64/python2.4/site-packages/japanese/aliases
# /usr/lib64/python2.4/site-packages/japanese/aliases/__init__.pyc matches /usr/lib64/python2.4/site-packages/japanese/aliases/__init__.py
import japanese.aliases # precompiled from /usr/lib64/python2.4/site-packages/japanese/aliases/__init__.pyc
import encodings # directory /usr/lib64/python2.4/encodings
# /usr/lib64/python2.4/encodings/__init__.pyc matches /usr/lib64/python2.4/encodings/__init__.py
import encodings # precompiled from /usr/lib64/python2.4/encodings/__init__.pyc
# /usr/lib64/python2.4/codecs.pyc matches /usr/lib64/python2.4/codecs.py
import codecs # precompiled from /usr/lib64/python2.4/codecs.pyc
import _codecs # builtin
# /usr/lib64/python2.4/encodings/aliases.pyc matches /usr/lib64/python2.4/encodings/aliases.py
import encodings.aliases # precompiled from /usr/lib64/python2.4/encodings/aliases.pyc
# /usr/lib64/python2.4/warnings.pyc matches /usr/lib64/python2.4/warnings.py
import warnings # precompiled from /usr/lib64/python2.4/warnings.pyc
# /usr/lib64/python2.4/linecache.pyc matches /usr/lib64/python2.4/linecache.py
import linecache # precompiled from /usr/lib64/python2.4/linecache.pyc
# /usr/lib64/python2.4/encodings/utf_8.pyc matches /usr/lib64/python2.4/encodings/utf_8.py
import encodings.utf_8 # precompiled from /usr/lib64/python2.4/encodings/utf_8.pyc
Python 2.4.3 (#1, May  1 2012, 13:55:48)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
dlopen("/usr/lib64/python2.4/lib-dynload/readline.so", 2);
import readline # dynamically loaded from /usr/lib64/python2.4/lib-dynload/readline.so
>>>

will47

unread,
Jul 31, 2012, 9:08:29 PM7/31/12
to pysp...@googlegroups.com
It's odd, though, because the 2.4 version of super() seems to have roughly the same interface as 2.7.

Seba

unread,
Aug 22, 2012, 7:45:12 AM8/22/12
to pysp...@googlegroups.com
Hi Will, 
  I'm not supporting python2.4 (and I'm not planning to). The error is weird though, super should work with new-style classes (the ones that extend from object), I'm extending from Exception. Maybe 'Exception' is not a new-style class in python 2.4.

Regards,

Seba.
Reply all
Reply to author
Forward
0 new messages