We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
scrape_document with trailing slash fails
```
▶ docker-compose exec web ./manage.py scrape_document https://developer.mozilla.org/en-US/docs/Web/CSS/ --depth=2
/usr/local/lib/python2.7/site-packages/django/utils/encoding.py:6: ImportWarning: Not importing directory '/app/locale': missing __init__.py
  import locale
/usr/local/lib/python2.7/site-packages/django/template/backends/jinja2.py:6: ImportWarning: Not importing directory '/app/jinja2': missing __init__.py
  import jinja2
/app/kuma/core/i18n.py:18: ImportWarning: Not importing directory '/app/kuma/core/jinja2': missing __init__.py
  from jinja2 import nodes
/usr/local/lib/python2.7/site-packages/decorator_include.py:20: RemovedInDjango20Warning: Importing from django.core.urlresolvers is deprecated in favor of django.urls.
  from django.core.urlresolvers import RegexURLPattern as URLPattern, RegexURLResolver as URLResolver
/usr/local/lib/python2.7/site-packages/soapbox/templatetags/soapbox.py:9: RemovedInDjango20Warning: assignment_tag() is deprecated. Use simple_tag() instead
  @register.assignment_tag(takes_context=True)
INFO: Scrape progress, cycle 1: 1 Initializing, 1 Gathering Requirements
INFO: Scrape progress, cycle 2: 3 Initializing, 1 Gathering Requirements, 1 Done
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/app/kuma/scrape/management/commands/scrape_document.py", line 47, in handle
    scraper.scrape()
  File "/app/kuma/scrape/scraper.py", line 182, in scrape
    dependencies = source.gather(self.requester, self.storage)
  File "/app/kuma/scrape/sources/base.py", line 192, in gather
    has_prereqs, data = self.load_prereqs(requester, storage)
  File "/app/kuma/scrape/sources/document_children.py", line 31, in load_prereqs
    data = response.json()
  File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/simplejson/__init__.py", line 516, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python2.7/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python2.7/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.scanner.JSONDecodeError: Expecting value: line 4 column 1 (char 3)
```

Note that if I retry without the trailing slash things work. I.e. `docker-compose exec web ./manage.py scrape_document https://developer.mozilla.org/en-US/docs/Web/CSS --depth=2`

Somewhere in there it assumes that the response is JSON when in fact the response status code is not OKish. 
scrape_document with trailing slash fails
```
▶ docker-compose exec web ./manage.py scrape_document https://developer.mozilla.org/en-US/docs/Web/CSS/ --depth=2
/usr/local/lib/python2.7/site-packages/django/utils/encoding.py:6: ImportWarning: Not importing directory '/app/locale': missing __init__.py
  import locale
/usr/local/lib/python2.7/site-packages/django/template/backends/jinja2.py:6: ImportWarning: Not importing directory '/app/jinja2': missing __init__.py
  import jinja2
/app/kuma/core/i18n.py:18: ImportWarning: Not importing directory '/app/kuma/core/jinja2': missing __init__.py
  from jinja2 import nodes
/usr/local/lib/python2.7/site-packages/decorator_include.py:20: RemovedInDjango20Warning: Importing from django.core.urlresolvers is deprecated in favor of django.urls.
  from django.core.urlresolvers import RegexURLPattern as URLPattern, RegexURLResolver as URLResolver
/usr/local/lib/python2.7/site-packages/soapbox/templatetags/soapbox.py:9: RemovedInDjango20Warning: assignment_tag() is deprecated. Use simple_tag() instead
  @register.assignment_tag(takes_context=True)
INFO: Scrape progress, cycle 1: 1 Initializing, 1 Gathering Requirements
INFO: Scrape progress, cycle 2: 3 Initializing, 1 Gathering Requirements, 1 Done
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/app/kuma/scrape/management/commands/scrape_document.py", line 47, in handle
    scraper.scrape()
  File "/app/kuma/scrape/scraper.py", line 182, in scrape
    dependencies = source.gather(self.requester, self.storage)
  File "/app/kuma/scrape/sources/base.py", line 192, in gather
    has_prereqs, data = self.load_prereqs(requester, storage)
  File "/app/kuma/scrape/sources/document_children.py", line 31, in load_prereqs
    data = response.json()
  File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/simplejson/__init__.py", line 516, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python2.7/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python2.7/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.scanner.JSONDecodeError: Expecting value: line 4 column 1 (char 3)
```

Note that if I retry without the trailing slash things work. I.e. `docker-compose exec web ./manage.py scrape_document https://developer.mozilla.org/en-US/docs/Web/CSS --depth=2`

Somewhere in there it assumes that the response is JSON when in fact the response status code is not OKish. 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kuma/scrape/management/commands/__init__.py`
Content:
```
1 """Common methods for scraping management commands."""
2 import logging
3 from argparse import ArgumentTypeError
4 
5 from django.core.management.base import BaseCommand
6 from django.utils.six.moves.urllib.parse import urlparse
7 
8 from kuma.scrape.scraper import Scraper
9 
10 
11 class ScrapeCommand(BaseCommand):
12     """Common base class for scraping management commands."""
13     def make_scraper(self, **options):
14         """Create a Scraper instance for management commands."""
15         return Scraper(**options)
16 
17     def parse_url_or_path(self, url_or_path):
18         if url_or_path.startswith('http'):
19             bits = urlparse(url_or_path)
20             host = bits.netloc
21             path = bits.path
22             ssl = (bits.scheme == 'https')
23         else:
24             host = 'wiki.developer.mozilla.org'
25             ssl = True
26             path = url_or_path
27         return host, ssl, path
28 
29     def setup_logging(self, verbosity):
30         """Update logger for desired verbosity."""
31 
32         if verbosity == 0:
33             level = logging.WARNING
34         elif verbosity == 1:  # default
35             level = logging.INFO
36         elif verbosity >= 2:
37             level = logging.DEBUG
38 
39         formatter = logging.Formatter('%(levelname)s: %(message)s')
40         console = logging.StreamHandler(self.stderr)
41         console.setLevel(level)
42         console.setFormatter(formatter)
43         logger = logging.getLogger('kuma.scraper')
44         logger.setLevel(level)
45         logger.addHandler(console)
46         logger.propagate = False
47 
48     def int_all_type(self, value):
49         """A command argument that can take an integer or 'all'."""
50         if value.strip().lower() == 'all':
51             return 'all'
52         try:
53             as_int = int(value)
54         except ValueError:
55             msg = "%r should be 'all' or an integer" % value
56             raise ArgumentTypeError(msg)
57         return as_int
58
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/kuma/scrape/management/commands/__init__.py b/kuma/scrape/management/commands/__init__.py
--- a/kuma/scrape/management/commands/__init__.py
+++ b/kuma/scrape/management/commands/__init__.py
@@ -18,12 +18,12 @@
         if url_or_path.startswith('http'):
             bits = urlparse(url_or_path)
             host = bits.netloc
-            path = bits.path
+            path = bits.path.rstrip('/')
             ssl = (bits.scheme == 'https')
         else:
             host = 'wiki.developer.mozilla.org'
             ssl = True
-            path = url_or_path
+            path = url_or_path.rstrip('/')
         return host, ssl, path
 
     def setup_logging(self, verbosity):

{"golden_diff": "diff --git a/kuma/scrape/management/commands/__init__.py b/kuma/scrape/management/commands/__init__.py\n--- a/kuma/scrape/management/commands/__init__.py\n+++ b/kuma/scrape/management/commands/__init__.py\n@@ -18,12 +18,12 @@\n         if url_or_path.startswith('http'):\n             bits = urlparse(url_or_path)\n             host = bits.netloc\n-            path = bits.path\n+            path = bits.path.rstrip('/')\n             ssl = (bits.scheme == 'https')\n         else:\n             host = 'wiki.developer.mozilla.org'\n             ssl = True\n-            path = url_or_path\n+            path = url_or_path.rstrip('/')\n         return host, ssl, path\n \n     def setup_logging(self, verbosity):\n", "issue": "scrape_document with trailing slash fails\n```\r\n\u25b6 docker-compose exec web ./manage.py scrape_document https://developer.mozilla.org/en-US/docs/Web/CSS/ --depth=2\r\n/usr/local/lib/python2.7/site-packages/django/utils/encoding.py:6: ImportWarning: Not importing directory '/app/locale': missing __init__.py\r\n  import locale\r\n/usr/local/lib/python2.7/site-packages/django/template/backends/jinja2.py:6: ImportWarning: Not importing directory '/app/jinja2': missing __init__.py\r\n  import jinja2\r\n/app/kuma/core/i18n.py:18: ImportWarning: Not importing directory '/app/kuma/core/jinja2': missing __init__.py\r\n  from jinja2 import nodes\r\n/usr/local/lib/python2.7/site-packages/decorator_include.py:20: RemovedInDjango20Warning: Importing from django.core.urlresolvers is deprecated in favor of django.urls.\r\n  from django.core.urlresolvers import RegexURLPattern as URLPattern, RegexURLResolver as URLResolver\r\n/usr/local/lib/python2.7/site-packages/soapbox/templatetags/soapbox.py:9: RemovedInDjango20Warning: assignment_tag() is deprecated. Use simple_tag() instead\r\n  @register.assignment_tag(takes_context=True)\r\nINFO: Scrape progress, cycle 1: 1 Initializing, 1 Gathering Requirements\r\nINFO: Scrape progress, cycle 2: 3 Initializing, 1 Gathering Requirements, 1 Done\r\nTraceback (most recent call last):\r\n  File \"./manage.py\", line 10, in <module>\r\n    execute_from_command_line(sys.argv)\r\n  File \"/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py\", line 364, in execute_from_command_line\r\n    utility.execute()\r\n  File \"/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py\", line 356, in execute\r\n    self.fetch_command(subcommand).run_from_argv(self.argv)\r\n  File \"/usr/local/lib/python2.7/site-packages/django/core/management/base.py\", line 283, in run_from_argv\r\n    self.execute(*args, **cmd_options)\r\n  File \"/usr/local/lib/python2.7/site-packages/django/core/management/base.py\", line 330, in execute\r\n    output = self.handle(*args, **options)\r\n  File \"/app/kuma/scrape/management/commands/scrape_document.py\", line 47, in handle\r\n    scraper.scrape()\r\n  File \"/app/kuma/scrape/scraper.py\", line 182, in scrape\r\n    dependencies = source.gather(self.requester, self.storage)\r\n  File \"/app/kuma/scrape/sources/base.py\", line 192, in gather\r\n    has_prereqs, data = self.load_prereqs(requester, storage)\r\n  File \"/app/kuma/scrape/sources/document_children.py\", line 31, in load_prereqs\r\n    data = response.json()\r\n  File \"/usr/local/lib/python2.7/site-packages/requests/models.py\", line 897, in json\r\n    return complexjson.loads(self.text, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/simplejson/__init__.py\", line 516, in loads\r\n    return _default_decoder.decode(s)\r\n  File \"/usr/local/lib/python2.7/site-packages/simplejson/decoder.py\", line 370, in decode\r\n    obj, end = self.raw_decode(s)\r\n  File \"/usr/local/lib/python2.7/site-packages/simplejson/decoder.py\", line 400, in raw_decode\r\n    return self.scan_once(s, idx=_w(s, idx).end())\r\nsimplejson.scanner.JSONDecodeError: Expecting value: line 4 column 1 (char 3)\r\n```\r\n\r\nNote that if I retry without the trailing slash things work. I.e. `docker-compose exec web ./manage.py scrape_document https://developer.mozilla.org/en-US/docs/Web/CSS --depth=2`\r\n\r\nSomewhere in there it assumes that the response is JSON when in fact the response status code is not OKish. \nscrape_document with trailing slash fails\n```\r\n\u25b6 docker-compose exec web ./manage.py scrape_document https://developer.mozilla.org/en-US/docs/Web/CSS/ --depth=2\r\n/usr/local/lib/python2.7/site-packages/django/utils/encoding.py:6: ImportWarning: Not importing directory '/app/locale': missing __init__.py\r\n  import locale\r\n/usr/local/lib/python2.7/site-packages/django/template/backends/jinja2.py:6: ImportWarning: Not importing directory '/app/jinja2': missing __init__.py\r\n  import jinja2\r\n/app/kuma/core/i18n.py:18: ImportWarning: Not importing directory '/app/kuma/core/jinja2': missing __init__.py\r\n  from jinja2 import nodes\r\n/usr/local/lib/python2.7/site-packages/decorator_include.py:20: RemovedInDjango20Warning: Importing from django.core.urlresolvers is deprecated in favor of django.urls.\r\n  from django.core.urlresolvers import RegexURLPattern as URLPattern, RegexURLResolver as URLResolver\r\n/usr/local/lib/python2.7/site-packages/soapbox/templatetags/soapbox.py:9: RemovedInDjango20Warning: assignment_tag() is deprecated. Use simple_tag() instead\r\n  @register.assignment_tag(takes_context=True)\r\nINFO: Scrape progress, cycle 1: 1 Initializing, 1 Gathering Requirements\r\nINFO: Scrape progress, cycle 2: 3 Initializing, 1 Gathering Requirements, 1 Done\r\nTraceback (most recent call last):\r\n  File \"./manage.py\", line 10, in <module>\r\n    execute_from_command_line(sys.argv)\r\n  File \"/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py\", line 364, in execute_from_command_line\r\n    utility.execute()\r\n  File \"/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py\", line 356, in execute\r\n    self.fetch_command(subcommand).run_from_argv(self.argv)\r\n  File \"/usr/local/lib/python2.7/site-packages/django/core/management/base.py\", line 283, in run_from_argv\r\n    self.execute(*args, **cmd_options)\r\n  File \"/usr/local/lib/python2.7/site-packages/django/core/management/base.py\", line 330, in execute\r\n    output = self.handle(*args, **options)\r\n  File \"/app/kuma/scrape/management/commands/scrape_document.py\", line 47, in handle\r\n    scraper.scrape()\r\n  File \"/app/kuma/scrape/scraper.py\", line 182, in scrape\r\n    dependencies = source.gather(self.requester, self.storage)\r\n  File \"/app/kuma/scrape/sources/base.py\", line 192, in gather\r\n    has_prereqs, data = self.load_prereqs(requester, storage)\r\n  File \"/app/kuma/scrape/sources/document_children.py\", line 31, in load_prereqs\r\n    data = response.json()\r\n  File \"/usr/local/lib/python2.7/site-packages/requests/models.py\", line 897, in json\r\n    return complexjson.loads(self.text, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/simplejson/__init__.py\", line 516, in loads\r\n    return _default_decoder.decode(s)\r\n  File \"/usr/local/lib/python2.7/site-packages/simplejson/decoder.py\", line 370, in decode\r\n    obj, end = self.raw_decode(s)\r\n  File \"/usr/local/lib/python2.7/site-packages/simplejson/decoder.py\", line 400, in raw_decode\r\n    return self.scan_once(s, idx=_w(s, idx).end())\r\nsimplejson.scanner.JSONDecodeError: Expecting value: line 4 column 1 (char 3)\r\n```\r\n\r\nNote that if I retry without the trailing slash things work. I.e. `docker-compose exec web ./manage.py scrape_document https://developer.mozilla.org/en-US/docs/Web/CSS --depth=2`\r\n\r\nSomewhere in there it assumes that the response is JSON when in fact the response status code is not OKish. \n", "before_files": [{"content": "\"\"\"Common methods for scraping management commands.\"\"\"\nimport logging\nfrom argparse import ArgumentTypeError\n\nfrom django.core.management.base import BaseCommand\nfrom django.utils.six.moves.urllib.parse import urlparse\n\nfrom kuma.scrape.scraper import Scraper\n\n\nclass ScrapeCommand(BaseCommand):\n    \"\"\"Common base class for scraping management commands.\"\"\"\n    def make_scraper(self, **options):\n        \"\"\"Create a Scraper instance for management commands.\"\"\"\n        return Scraper(**options)\n\n    def parse_url_or_path(self, url_or_path):\n        if url_or_path.startswith('http'):\n            bits = urlparse(url_or_path)\n            host = bits.netloc\n            path = bits.path\n            ssl = (bits.scheme == 'https')\n        else:\n            host = 'wiki.developer.mozilla.org'\n            ssl = True\n            path = url_or_path\n        return host, ssl, path\n\n    def setup_logging(self, verbosity):\n        \"\"\"Update logger for desired verbosity.\"\"\"\n\n        if verbosity == 0:\n            level = logging.WARNING\n        elif verbosity == 1:  # default\n            level = logging.INFO\n        elif verbosity >= 2:\n            level = logging.DEBUG\n\n        formatter = logging.Formatter('%(levelname)s: %(message)s')\n        console = logging.StreamHandler(self.stderr)\n        console.setLevel(level)\n        console.setFormatter(formatter)\n        logger = logging.getLogger('kuma.scraper')\n        logger.setLevel(level)\n        logger.addHandler(console)\n        logger.propagate = False\n\n    def int_all_type(self, value):\n        \"\"\"A command argument that can take an integer or 'all'.\"\"\"\n        if value.strip().lower() == 'all':\n            return 'all'\n        try:\n            as_int = int(value)\n        except ValueError:\n            msg = \"%r should be 'all' or an integer\" % value\n            raise ArgumentTypeError(msg)\n        return as_int\n", "path": "kuma/scrape/management/commands/__init__.py"}], "after_files": [{"content": "\"\"\"Common methods for scraping management commands.\"\"\"\nimport logging\nfrom argparse import ArgumentTypeError\n\nfrom django.core.management.base import BaseCommand\nfrom django.utils.six.moves.urllib.parse import urlparse\n\nfrom kuma.scrape.scraper import Scraper\n\n\nclass ScrapeCommand(BaseCommand):\n    \"\"\"Common base class for scraping management commands.\"\"\"\n    def make_scraper(self, **options):\n        \"\"\"Create a Scraper instance for management commands.\"\"\"\n        return Scraper(**options)\n\n    def parse_url_or_path(self, url_or_path):\n        if url_or_path.startswith('http'):\n            bits = urlparse(url_or_path)\n            host = bits.netloc\n            path = bits.path.rstrip('/')\n            ssl = (bits.scheme == 'https')\n        else:\n            host = 'wiki.developer.mozilla.org'\n            ssl = True\n            path = url_or_path.rstrip('/')\n        return host, ssl, path\n\n    def setup_logging(self, verbosity):\n        \"\"\"Update logger for desired verbosity.\"\"\"\n\n        if verbosity == 0:\n            level = logging.WARNING\n        elif verbosity == 1:  # default\n            level = logging.INFO\n        elif verbosity >= 2:\n            level = logging.DEBUG\n\n        formatter = logging.Formatter('%(levelname)s: %(message)s')\n        console = logging.StreamHandler(self.stderr)\n        console.setLevel(level)\n        console.setFormatter(formatter)\n        logger = logging.getLogger('kuma.scraper')\n        logger.setLevel(level)\n        logger.addHandler(console)\n        logger.propagate = False\n\n    def int_all_type(self, value):\n        \"\"\"A command argument that can take an integer or 'all'.\"\"\"\n        if value.strip().lower() == 'all':\n            return 'all'\n        try:\n            as_int = int(value)\n        except ValueError:\n            msg = \"%r should be 'all' or an integer\" % value\n            raise ArgumentTypeError(msg)\n        return as_int\n", "path": "kuma/scrape/management/commands/__init__.py"}]}