We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Audit log crash on IPv6
Affected version: 8.5.0

I was just saving some preferences and faced this error:

```
DataError: ERREUR:  syntaxe en entrée invalide pour le type inet : « 2001 »
LINE 1: ...oursenaud@gpcsolutions.fr', 2, NULL, 1, NULL, 11, '2001', 'e...
                                                             ^

SQL: INSERT INTO "sentry_auditlogentry" ("organization_id", "actor_label", "actor_id", "actor_key_id", "target_object", "target_user_id", "event", "ip_address", "data", "datetime") VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING "sentry_auditlogentry"."id"
```

Looks like IPv6 addresses are not handled properly.

Also reproduced by deleting a project.
Oddly this wasn't triggered on project creation and my IPv4 was logged instead of my IPv6.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/sentry/middleware/proxy.py`
Content:
```
1 from __future__ import absolute_import
2 
3 
4 class SetRemoteAddrFromForwardedFor(object):
5     def process_request(self, request):
6         try:
7             real_ip = request.META['HTTP_X_FORWARDED_FOR']
8         except KeyError:
9             pass
10         else:
11             # HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs.
12             # Take just the first one.
13             real_ip = real_ip.split(",")[0]
14             if ':' in real_ip:
15                 real_ip = real_ip.split(':', 1)[0]
16             request.META['REMOTE_ADDR'] = real_ip
17 
18 
19 class ContentLengthHeaderMiddleware(object):
20     """
21     Ensure that we have a proper Content-Length/Transfer-Encoding header
22     """
23 
24     def process_response(self, request, response):
25         if 'Transfer-Encoding' in response or 'Content-Length' in response:
26             return response
27 
28         if not response.streaming:
29             response['Content-Length'] = str(len(response.content))
30 
31         return response
32
```
--- 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/src/sentry/middleware/proxy.py b/src/sentry/middleware/proxy.py
--- a/src/sentry/middleware/proxy.py
+++ b/src/sentry/middleware/proxy.py
@@ -11,7 +11,8 @@
             # HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs.
             # Take just the first one.
             real_ip = real_ip.split(",")[0]
-            if ':' in real_ip:
+            if ':' in real_ip and '.' in real_ip:
+                # Strip the port number off of an IPv4 FORWARDED_FOR entry.
                 real_ip = real_ip.split(':', 1)[0]
             request.META['REMOTE_ADDR'] = real_ip

{"golden_diff": "diff --git a/src/sentry/middleware/proxy.py b/src/sentry/middleware/proxy.py\n--- a/src/sentry/middleware/proxy.py\n+++ b/src/sentry/middleware/proxy.py\n@@ -11,7 +11,8 @@\n             # HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs.\n             # Take just the first one.\n             real_ip = real_ip.split(\",\")[0]\n-            if ':' in real_ip:\n+            if ':' in real_ip and '.' in real_ip:\n+                # Strip the port number off of an IPv4 FORWARDED_FOR entry.\n                 real_ip = real_ip.split(':', 1)[0]\n             request.META['REMOTE_ADDR'] = real_ip\n", "issue": "Audit log crash on IPv6\nAffected version: 8.5.0\n\nI was just saving some preferences and faced this error:\n\n```\nDataError: ERREUR:  syntaxe en entr\u00e9e invalide pour le type inet : \u00ab 2001 \u00bb\nLINE 1: ...oursenaud@gpcsolutions.fr', 2, NULL, 1, NULL, 11, '2001', 'e...\n                                                             ^\n\nSQL: INSERT INTO \"sentry_auditlogentry\" (\"organization_id\", \"actor_label\", \"actor_id\", \"actor_key_id\", \"target_object\", \"target_user_id\", \"event\", \"ip_address\", \"data\", \"datetime\") VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING \"sentry_auditlogentry\".\"id\"\n```\n\nLooks like IPv6 addresses are not handled properly.\n\nAlso reproduced by deleting a project.\nOddly this wasn't triggered on project creation and my IPv4 was logged instead of my IPv6.\n\n", "before_files": [{"content": "from __future__ import absolute_import\n\n\nclass SetRemoteAddrFromForwardedFor(object):\n    def process_request(self, request):\n        try:\n            real_ip = request.META['HTTP_X_FORWARDED_FOR']\n        except KeyError:\n            pass\n        else:\n            # HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs.\n            # Take just the first one.\n            real_ip = real_ip.split(\",\")[0]\n            if ':' in real_ip:\n                real_ip = real_ip.split(':', 1)[0]\n            request.META['REMOTE_ADDR'] = real_ip\n\n\nclass ContentLengthHeaderMiddleware(object):\n    \"\"\"\n    Ensure that we have a proper Content-Length/Transfer-Encoding header\n    \"\"\"\n\n    def process_response(self, request, response):\n        if 'Transfer-Encoding' in response or 'Content-Length' in response:\n            return response\n\n        if not response.streaming:\n            response['Content-Length'] = str(len(response.content))\n\n        return response\n", "path": "src/sentry/middleware/proxy.py"}], "after_files": [{"content": "from __future__ import absolute_import\n\n\nclass SetRemoteAddrFromForwardedFor(object):\n    def process_request(self, request):\n        try:\n            real_ip = request.META['HTTP_X_FORWARDED_FOR']\n        except KeyError:\n            pass\n        else:\n            # HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs.\n            # Take just the first one.\n            real_ip = real_ip.split(\",\")[0]\n            if ':' in real_ip and '.' in real_ip:\n                # Strip the port number off of an IPv4 FORWARDED_FOR entry.\n                real_ip = real_ip.split(':', 1)[0]\n            request.META['REMOTE_ADDR'] = real_ip\n\n\nclass ContentLengthHeaderMiddleware(object):\n    \"\"\"\n    Ensure that we have a proper Content-Length/Transfer-Encoding header\n    \"\"\"\n\n    def process_response(self, request, response):\n        if 'Transfer-Encoding' in response or 'Content-Length' in response:\n            return response\n\n        if not response.streaming:\n            response['Content-Length'] = str(len(response.content))\n\n        return response\n", "path": "src/sentry/middleware/proxy.py"}]}