Develop > Developer Reference > Creating Discovery and Integration Adapters > Developing Jython Adapters > Create Jython Code > Troubleshooting - Migration from Jython Version 2.1 to 2.5.3

Troubleshooting Migration from Jython Version 2.1 to 2.5.3

Universal Discovery now uses Jython version 2.5.3. All out-of-the-box scripts have been properly migrated. If you developed your own Jython scripts prior to this upgrade for use by Discovery, you may run into the following issues and have to make the fixes indicated.

Note You must be an experienced Jython developer to make these changes.

String Formatting

  • Error message:TypeError: int argument required
  • Possible cause: Using string formatting to decimal integer from string variable containing integer data.
  • Problematic Jython 2.1 code:

    variable = "43"
    print "%d" % variable
  • Correct Jython 2.5.3 code:

    variable = "43"
    print "%s" % variable

    or

    variable = "43"
    print "%d" % int(variable)

Checking String Type

The code below may not work correctly if input contains unicode strings:

  • Problematic Jython 2.1 code:

    isinstance(unicodeStringVariable,'')
  • Correct Jython 2.5.3 code:

    isinstance(unicodeStringVariable,basestring)

    The comparison should be done with basestring to test whether an object is an instance of str or unicode.

Non-ASCII character in file

  • Error Message:

    SyntaxError: Non-ASCII character in file 'x', , but no encoding declared;
    see http://www.python.org/peps/pep-0263.html for details
  • Correct Jython 2.5.3 code: (add this to the first line in the file)

    # coding: utf-8

Import sub-packages

  • Error message:

    AttributeError: 'module' object has no attribute 'sub_package_name'

  • Possible cause: A sub-package is imported without explicitly specifying the name of sub-package in the import statement.
  • Problematic Jython 2.1 code:

    import a
    print dir(a.b)

    The sub-package is not explicitly imported.

  • Correct Jython 2.5.3 code:

    import a.b

    or

    from a import b

Iterator Changes

Starting from Jython 2.2, the __iter__ method is used to loop over a collection in the scope of a for-in block. The iterator should implement the next method, returning an appropriate element or throw the StopIteration error if it reached the end of the collection. If the __iter__ method is not implemented, the getitem method is used instead.

Raising Exceptions

  • Jython 2.1 method for raising exceptions is obsolete:

    raise Exception, 'Failed getting contents of file'

  • Recommended Jython 2.5.3 method for raising exceptions:

    raise Exception('Failed getting contents of file')