Error Message TypeError: exceptions must be old-style classes or derived from BaseException, not unicode

1,307 views
Skip to first unread message

jean...@gmail.com

unread,
Jun 21, 2017, 9:48:03 AM6/21/17
to robotframework-users
Hello,

I want to do some basic automated login with username and passwort and click on "Login" button with my samsung smartphone. I have setup a basic robotframework project in eclipse (with robot plugin) and the application runs up to the point where it automatically starts the app on the smartphone. but after that, it stops. The error message that I get is TypeError: exceptions must be old-style classes or derived from BaseException, not unicode. I cannot figure out where the problem lies. I am using Robotframwork 3.0.2 and Python 2.7 on a Windows 7 machine. Can anyone help me please?

Pekka Klärck

unread,
Jun 21, 2017, 9:54:45 AM6/21/17
to jean...@gmail.com, robotframework-users
Somewhere your code tries to raise a Unicode string as an exception:

Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> raise u'Hello'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: exceptions must be old-style classes or derived from
BaseException, not unicode

If you are working with legacy code, this may be due to the code
deliberately doing that. Python actually supported raising strings as
exceptions earlier, but that support was deprecated long time ago and
removed in Python 2.6 or perhaps already earlier.

Cheers,
.peke
> --
> You received this message because you are subscribed to the Google Groups
> "robotframework-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to robotframework-u...@googlegroups.com.
> To post to this group, send email to robotframe...@googlegroups.com.
> Visit this group at https://groups.google.com/group/robotframework-users.
> For more options, visit https://groups.google.com/d/optout.



--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

jean...@gmail.com

unread,
Jun 21, 2017, 10:35:45 AM6/21/17
to robotframework-users
Thanks very much Peke for your reply.

Basically, the only code that I have is that of the Robotframework itself (version 3.0.2) and Python and it´s libraries. And also, I am using the AppiumLibray.

You wrote "If you are working with legacy code, this may be due to the code deliberately doing that." The only "legacy" code could only be the .py files from the Robotframework, Python (and libraries) and AppiumLibrary.
Correct?
What would be a syntax example so I can browse through the .py file to find the source of the problem?

The problem is, I do not have (and know) any means of debugging so I can see in which file and on which line the TypeError appears. So if you know any method of debugging, that would be nice.

Thanks!
Message has been deleted

Pekka Klärck

unread,
Jun 21, 2017, 11:21:00 AM6/21/17
to jean...@gmail.com, robotframework-users
Try running tests with `--loglevel DEBUG`. This enables traceback to
be shown in log files.

Cheers,
.peke

jean...@gmail.com

unread,
Jun 22, 2017, 9:03:37 AM6/22/17
to robotframework-users, jean...@gmail.com
Hello,


I have tried running with the option --loglevel DEBUG but that doesnt work because i getting a

Unknown option: --
usage: C:\Python36\python.exe [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.

In the meanwhile, I have changed my setup using Python 3.6.1, Robotframework 3.0.2 and Robotframework AppiumLibrary 1.4.4.

When executing, I am not getting the TypeError exception as before, but now the following:

AttributeError: 'dict' object has no attribute 'has_key'


Also, I am getting the following Warning in the  debug report from Eclipse:

C:\Python36\lib\runpy.py:125: RuntimeWarning: 'robot.run' found in sys.modules after import of package 'robot', but prior to execution of 'robot.run'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))


Any hints/ideas?

Thanks in advance!

Pekka Klärck

unread,
Jun 22, 2017, 9:10:02 AM6/22/17
to jean...@gmail.com, robotframework-users
2017-06-22 16:03 GMT+03:00 <jean...@gmail.com>:
>
> I have tried running with the option --loglevel DEBUG but that doesnt work
> because i getting a
>
> Unknown option: --
> usage: C:\Python36\python.exe [option] ... [-c cmd | -m mod | file | -]
> [arg] ...
> Try `python -h' for more information.

That `--loglevel debug` was an option to Robot. Now you are passing it
to Python.

> In the meanwhile, I have changed my setup using Python 3.6.1, Robotframework
> 3.0.2 and Robotframework AppiumLibrary 1.4.4.
>
> When executing, I am not getting the TypeError exception as before, but now
> the following:
>
> AttributeError: 'dict' object has no attribute 'has_key'

Apparently some code isn't Python 3 compatible. `dict` objects don't
have `has_key` anymore in Python 3. Code that uses
`mydict.has_key(mykey)` should be changed to `mykey in mydict`.

> Also, I am getting the following Warning in the debug report from Eclipse:
>
> C:\Python36\lib\runpy.py:125: RuntimeWarning: 'robot.run' found in
> sys.modules after import of package 'robot', but prior to execution of
> 'robot.run'; this may result in unpredictable behaviour
> warn(RuntimeWarning(msg))

This is a know issue with Robot when using Python 3.6 on Windows.
Luckily this annoying warning can be ignored:
https://github.com/robotframework/robotframework/issues/2552

Cheers,
.peke

jean...@gmail.com

unread,
Jun 23, 2017, 4:29:41 AM6/23/17
to robotframework-users
Hello,


Thanks very much for the support. It´s now running fine.

Regards.



Am Mittwoch, 21. Juni 2017 15:48:03 UTC+2 schrieb jean...@gmail.com:
Reply all
Reply to author
Forward
0 new messages