This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author porton
Recipients porton
Date 2018-07-22.19:58:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1532289510.54.0.56676864532.issue34191@psf.upfronthosting.co.za>
In-reply-to
Content
argparse produces a long unreadable, non-understandable for non-programmers error message when a subparser is not specified in the command line.

Note that the below message contains Ubuntu specifics, but it seems it would be nearly as unclear on other OSes too.

The worst thing about this error message is that to produce something readable instead I need to somehow parse the command string (or at least to catch TypeError).

$ python3.7 test.py 
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    args = parser.parse_args()
  File "/usr/lib/python3.7/argparse.py", line 1754, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "/usr/lib/python3.7/argparse.py", line 1786, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/usr/lib/python3.7/argparse.py", line 2021, in _parse_known_args
    ', '.join(required_actions))
TypeError: sequence item 0: expected str instance, NoneType found
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    args = parser.parse_args()
  File "/usr/lib/python3.7/argparse.py", line 1754, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "/usr/lib/python3.7/argparse.py", line 1786, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/usr/lib/python3.7/argparse.py", line 2021, in _parse_known_args
    ', '.join(required_actions))
TypeError: sequence item 0: expected str instance, NoneType found

The script follows.

#!/usr/bin/env python

import argparse

parser = argparse.ArgumentParser(description="Automatically process XML")
subparsers = parser.add_subparsers(title='subcommands')

chain_parser = subparsers.add_parser('chain', aliases=['c'], help='Automatically run a chain of transformations')

args = parser.parse_args()
History
Date User Action Args
2018-07-22 19:58:30portonsetrecipients: + porton
2018-07-22 19:58:30portonsetmessageid: <1532289510.54.0.56676864532.issue34191@psf.upfronthosting.co.za>
2018-07-22 19:58:30portonlinkissue34191 messages
2018-07-22 19:58:30portoncreate