We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Import of Bezirksregionen stopped working
`$ manage.py import_geodata --gdal-legacy`

Leads to a `KeyError`, probably the data format has changed.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `meinberlin/apps/maps/management/commands/import_geodata.py`
Content:
```
1 import json
2 import os
3 import subprocess
4 import sys
5 
6 from django.core.management.base import BaseCommand
7 
8 from meinberlin.apps.maps import models as map_models
9 
10 
11 class Command(BaseCommand):
12     help = 'Create map presets for berlin GEO-Data'
13 
14     def add_arguments(self, parser):
15         parser.add_argument(
16             '--gdal-legacy',
17             action='store_true',
18             dest='gdal_legacy',
19             default=False,
20             help='GDAL version <= 1.10',
21         )
22 
23     def handle(self, *args, **options):
24         self.is_gdal_legacy = options['gdal_legacy']
25         self._import_districts()
26         self._import_regions()
27 
28     def _import_districts(self):
29         category = self._preset_category('Berlin')
30         tmpfile = '/tmp/bezirke.json'
31         url = 'http://fbinter.stadt-berlin.de/fb/' \
32               'wfs/geometry/senstadt/re_bezirke/'
33         self._download_geodata(tmpfile, url, 'fis:re_bezirke')
34         data = json.load(open(tmpfile, 'r'))
35         for feature in data['features']:
36             district = feature['properties']['spatial_alias']
37             if not map_models.MapPreset.objects.filter(name=district).exists():
38                 self._create_map_preset(district, feature, category)
39         os.remove(tmpfile)
40 
41     def _import_regions(self):
42         url = 'http://fbinter.stadt-berlin.de/fb/' \
43               'wfs/geometry/senstadt/re_bezirksregion'
44         tmpfile = '/tmp/bezirksregions.json'
45         self._download_geodata(tmpfile, url,
46                                'fis:re_bezirksregion')
47         data = json.load(open(tmpfile, 'r'))
48         for feature in data['features']:
49             district = feature['properties']['BEZIRK']
50             region = feature['properties']['BZR_NAME']
51             category = self._preset_category(district)
52             if not map_models.MapPreset.objects.filter(name=region).exists():
53                 self._create_map_preset(region, feature, category)
54         os.remove(tmpfile)
55 
56     def _preset_category(self, name):
57         category, _ = \
58             map_models.MapPresetCategory.objects.get_or_create(name=name)
59         return category
60 
61     def _create_map_preset(self, name, feature, category):
62         polygon = {
63             'type': 'FeatureCollection',
64             'features': [feature]
65         }
66         map_preset = map_models.MapPreset(
67             name=name,
68             polygon=polygon,
69             category=category
70         )
71         map_preset.save()
72 
73     def _download_geodata(self, filename: str, url: str, layer: str):
74         try:
75             os.remove(filename)
76         except:
77             pass
78 
79         src = 'WFS:{}{}'.format(
80             url,
81             '?TYPENAMES=GML2' if self.is_gdal_legacy else ''
82         )
83         try:
84             print('Trying to download file from {}'.format(url))
85             subprocess.check_call([
86                 'ogr2ogr', '-s_srs', 'EPSG:25833', '-t_srs', 'WGS84',
87                 '-f', 'geoJSON', filename, src, layer
88             ])
89         except FileNotFoundError as e:
90             print('Make sure ogr2ogr is installed and in user PATH.')
91             sys.exit(e)
92
```
--- 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/meinberlin/apps/maps/management/commands/import_geodata.py b/meinberlin/apps/maps/management/commands/import_geodata.py
--- a/meinberlin/apps/maps/management/commands/import_geodata.py
+++ b/meinberlin/apps/maps/management/commands/import_geodata.py
@@ -40,13 +40,13 @@
 
     def _import_regions(self):
         url = 'http://fbinter.stadt-berlin.de/fb/' \
-              'wfs/geometry/senstadt/re_bezirksregion'
+              'wfs/geometry/senstadt/re_bezirksregion/'
         tmpfile = '/tmp/bezirksregions.json'
         self._download_geodata(tmpfile, url,
                                'fis:re_bezirksregion')
         data = json.load(open(tmpfile, 'r'))
         for feature in data['features']:
-            district = feature['properties']['BEZIRK']
+            district = feature['properties']['BEZNAME']
             region = feature['properties']['BZR_NAME']
             category = self._preset_category(district)
             if not map_models.MapPreset.objects.filter(name=region).exists():
@@ -78,7 +78,7 @@
 
         src = 'WFS:{}{}'.format(
             url,
-            '?TYPENAMES=GML2' if self.is_gdal_legacy else ''
+            '?VERSION=1.1.0' if self.is_gdal_legacy else ''
         )
         try:
             print('Trying to download file from {}'.format(url))

{"golden_diff": "diff --git a/meinberlin/apps/maps/management/commands/import_geodata.py b/meinberlin/apps/maps/management/commands/import_geodata.py\n--- a/meinberlin/apps/maps/management/commands/import_geodata.py\n+++ b/meinberlin/apps/maps/management/commands/import_geodata.py\n@@ -40,13 +40,13 @@\n \n     def _import_regions(self):\n         url = 'http://fbinter.stadt-berlin.de/fb/' \\\n-              'wfs/geometry/senstadt/re_bezirksregion'\n+              'wfs/geometry/senstadt/re_bezirksregion/'\n         tmpfile = '/tmp/bezirksregions.json'\n         self._download_geodata(tmpfile, url,\n                                'fis:re_bezirksregion')\n         data = json.load(open(tmpfile, 'r'))\n         for feature in data['features']:\n-            district = feature['properties']['BEZIRK']\n+            district = feature['properties']['BEZNAME']\n             region = feature['properties']['BZR_NAME']\n             category = self._preset_category(district)\n             if not map_models.MapPreset.objects.filter(name=region).exists():\n@@ -78,7 +78,7 @@\n \n         src = 'WFS:{}{}'.format(\n             url,\n-            '?TYPENAMES=GML2' if self.is_gdal_legacy else ''\n+            '?VERSION=1.1.0' if self.is_gdal_legacy else ''\n         )\n         try:\n             print('Trying to download file from {}'.format(url))\n", "issue": "Import of Bezirksregionen stopped working\n`$ manage.py import_geodata --gdal-legacy`\r\n\r\nLeads to a `KeyError`, probably the data format has changed.\r\n\n", "before_files": [{"content": "import json\nimport os\nimport subprocess\nimport sys\n\nfrom django.core.management.base import BaseCommand\n\nfrom meinberlin.apps.maps import models as map_models\n\n\nclass Command(BaseCommand):\n    help = 'Create map presets for berlin GEO-Data'\n\n    def add_arguments(self, parser):\n        parser.add_argument(\n            '--gdal-legacy',\n            action='store_true',\n            dest='gdal_legacy',\n            default=False,\n            help='GDAL version <= 1.10',\n        )\n\n    def handle(self, *args, **options):\n        self.is_gdal_legacy = options['gdal_legacy']\n        self._import_districts()\n        self._import_regions()\n\n    def _import_districts(self):\n        category = self._preset_category('Berlin')\n        tmpfile = '/tmp/bezirke.json'\n        url = 'http://fbinter.stadt-berlin.de/fb/' \\\n              'wfs/geometry/senstadt/re_bezirke/'\n        self._download_geodata(tmpfile, url, 'fis:re_bezirke')\n        data = json.load(open(tmpfile, 'r'))\n        for feature in data['features']:\n            district = feature['properties']['spatial_alias']\n            if not map_models.MapPreset.objects.filter(name=district).exists():\n                self._create_map_preset(district, feature, category)\n        os.remove(tmpfile)\n\n    def _import_regions(self):\n        url = 'http://fbinter.stadt-berlin.de/fb/' \\\n              'wfs/geometry/senstadt/re_bezirksregion'\n        tmpfile = '/tmp/bezirksregions.json'\n        self._download_geodata(tmpfile, url,\n                               'fis:re_bezirksregion')\n        data = json.load(open(tmpfile, 'r'))\n        for feature in data['features']:\n            district = feature['properties']['BEZIRK']\n            region = feature['properties']['BZR_NAME']\n            category = self._preset_category(district)\n            if not map_models.MapPreset.objects.filter(name=region).exists():\n                self._create_map_preset(region, feature, category)\n        os.remove(tmpfile)\n\n    def _preset_category(self, name):\n        category, _ = \\\n            map_models.MapPresetCategory.objects.get_or_create(name=name)\n        return category\n\n    def _create_map_preset(self, name, feature, category):\n        polygon = {\n            'type': 'FeatureCollection',\n            'features': [feature]\n        }\n        map_preset = map_models.MapPreset(\n            name=name,\n            polygon=polygon,\n            category=category\n        )\n        map_preset.save()\n\n    def _download_geodata(self, filename: str, url: str, layer: str):\n        try:\n            os.remove(filename)\n        except:\n            pass\n\n        src = 'WFS:{}{}'.format(\n            url,\n            '?TYPENAMES=GML2' if self.is_gdal_legacy else ''\n        )\n        try:\n            print('Trying to download file from {}'.format(url))\n            subprocess.check_call([\n                'ogr2ogr', '-s_srs', 'EPSG:25833', '-t_srs', 'WGS84',\n                '-f', 'geoJSON', filename, src, layer\n            ])\n        except FileNotFoundError as e:\n            print('Make sure ogr2ogr is installed and in user PATH.')\n            sys.exit(e)\n", "path": "meinberlin/apps/maps/management/commands/import_geodata.py"}], "after_files": [{"content": "import json\nimport os\nimport subprocess\nimport sys\n\nfrom django.core.management.base import BaseCommand\n\nfrom meinberlin.apps.maps import models as map_models\n\n\nclass Command(BaseCommand):\n    help = 'Create map presets for berlin GEO-Data'\n\n    def add_arguments(self, parser):\n        parser.add_argument(\n            '--gdal-legacy',\n            action='store_true',\n            dest='gdal_legacy',\n            default=False,\n            help='GDAL version <= 1.10',\n        )\n\n    def handle(self, *args, **options):\n        self.is_gdal_legacy = options['gdal_legacy']\n        self._import_districts()\n        self._import_regions()\n\n    def _import_districts(self):\n        category = self._preset_category('Berlin')\n        tmpfile = '/tmp/bezirke.json'\n        url = 'http://fbinter.stadt-berlin.de/fb/' \\\n              'wfs/geometry/senstadt/re_bezirke/'\n        self._download_geodata(tmpfile, url, 'fis:re_bezirke')\n        data = json.load(open(tmpfile, 'r'))\n        for feature in data['features']:\n            district = feature['properties']['spatial_alias']\n            if not map_models.MapPreset.objects.filter(name=district).exists():\n                self._create_map_preset(district, feature, category)\n        os.remove(tmpfile)\n\n    def _import_regions(self):\n        url = 'http://fbinter.stadt-berlin.de/fb/' \\\n              'wfs/geometry/senstadt/re_bezirksregion/'\n        tmpfile = '/tmp/bezirksregions.json'\n        self._download_geodata(tmpfile, url,\n                               'fis:re_bezirksregion')\n        data = json.load(open(tmpfile, 'r'))\n        for feature in data['features']:\n            district = feature['properties']['BEZNAME']\n            region = feature['properties']['BZR_NAME']\n            category = self._preset_category(district)\n            if not map_models.MapPreset.objects.filter(name=region).exists():\n                self._create_map_preset(region, feature, category)\n        os.remove(tmpfile)\n\n    def _preset_category(self, name):\n        category, _ = \\\n            map_models.MapPresetCategory.objects.get_or_create(name=name)\n        return category\n\n    def _create_map_preset(self, name, feature, category):\n        polygon = {\n            'type': 'FeatureCollection',\n            'features': [feature]\n        }\n        map_preset = map_models.MapPreset(\n            name=name,\n            polygon=polygon,\n            category=category\n        )\n        map_preset.save()\n\n    def _download_geodata(self, filename: str, url: str, layer: str):\n        try:\n            os.remove(filename)\n        except:\n            pass\n\n        src = 'WFS:{}{}'.format(\n            url,\n            '?VERSION=1.1.0' if self.is_gdal_legacy else ''\n        )\n        try:\n            print('Trying to download file from {}'.format(url))\n            subprocess.check_call([\n                'ogr2ogr', '-s_srs', 'EPSG:25833', '-t_srs', 'WGS84',\n                '-f', 'geoJSON', filename, src, layer\n            ])\n        except FileNotFoundError as e:\n            print('Make sure ogr2ogr is installed and in user PATH.')\n            sys.exit(e)\n", "path": "meinberlin/apps/maps/management/commands/import_geodata.py"}]}