'NoneType' object has no attribute 'endswith'
Here is the stack-trace:
```
{{{
Traceback (most recent call last):
File "/Users/brianray/GitHub/methodical-feature-
space/fserve/./manage.py", line 21, in <module>
main()
File "/Users/brianray/GitHub/methodical-feature-
space/fserve/./manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/opt/anaconda3/lib/python3.9/site-
packages/django/core/management/__init__.py", line 446, in
execute_from_command_line
utility.execute()
File "/opt/anaconda3/lib/python3.9/site-
packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/anaconda3/lib/python3.9/site-
packages/django/core/management/base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/anaconda3/lib/python3.9/site-
packages/django/core/management/base.py", line 460, in execute
output = self.handle(*args, **options)
File "/Users/brianray/GitHub/methodical-feature-
space/fserve/ftasks/management/commands/dumpurls.py", line 15, in handle
self.stdout.write(pprint.pprint(urls))
File "/opt/anaconda3/lib/python3.9/site-
packages/django/core/management/base.py", line 169, in write
if ending and not msg.endswith(ending):
AttributeError: 'NoneType' object has no attribute 'endswith'
}}}
```
To reproduce take this code:
```
{{{
from django.core.management.base import BaseCommand
from django.urls import get_resolver
import pprint
class Command(BaseCommand):
help = 'dumps all the endpoint urls'
def handle(self, *args, **options):
urls = {pat.name: str(pat.pattern._route) for pat in
get_resolver().url_patterns
if getattr(pat, "name", None)}
self.stdout.write(self.style.SUCCESS('Here are the urls: \n\n'))
self.stdout.write(pprint.pprint(urls))
self.stdout.write("\n")
return True
}}}
```
put into {BASE}/{module}/management/commands ...
Django==4.0.5
--
Ticket URL: <https://code.djangoproject.com/ticket/34020>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => invalid
Comment:
Traceback can clearly points at the
`self.stdout.write(pprint.pprint(urls))` call being the origin of the
issue.
`pprint.pprint`
[https://docs.python.org/3/library/pprint.html?highlight=pprint#pprint.pprint
returns] `None`, `self.stdout.write` expects a string, and the error
messages clears state `'NoneType' object has no attribute 'endswith'`.
Please avoid using this ticket tracker unless you have confirmed this is
an issue with Django through TicketClosingReasons/UseSupportChannels.
--
Ticket URL: <https://code.djangoproject.com/ticket/34020#comment:1>