We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Cannot identify .fits file
### What did you do?
Tried using pillow for opening/handling a .fits file for training a machine learning model. According to the documentation opening/reading fits files should be enabled? Or am I misunderstanding how a fits file should be opened? 


From Issue [4054](https://github.com/python-pillow/Pillow/issues/4054)/ PR 6056

> I've created PR https://github.com/python-pillow/Pillow/pull/6056 to resolve this. If that is merged, you should no longer have to worry about register_handler(), but can instead just Image.open("sample.fits").


### What did you expect to happen?
Not recieving a "cannot identify error" while using Image.open. Expected the function to work as with other supported file formats. The .fits files in question are not corrupted, and can be opened as normal with other software. 

### What happened?
```python
from PIL import Image
with Image.open('example.fits') as im:
    im.verify()
```

```
---------------------------------------------------------------------------
UnidentifiedImageError                    Traceback (most recent call last)
Cell In [38], line 2
      1 from PIL import FitsImagePlugin, ImageFile
----> 2 with Image.open('example.fits') as im:
      3     im.verify()

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PIL\Image.py:3186, in open(fp, mode, formats)
   3184 for message in accept_warnings:
   3185     warnings.warn(message)
-> 3186 raise UnidentifiedImageError(
   3187     "cannot identify image file %r" % (filename if filename else fp)
   3188 )

UnidentifiedImageError: cannot identify image file 'example.fits'
```
### What are your OS, Python and Pillow versions?

* OS: windows 10
* Python: 3.10
* Pillow: 9.3.0

<!--
Please include **code** that reproduces the issue and whenever possible, an **image** that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.

The best reproductions are self-contained scripts with minimal dependencies. If you are using a framework such as Plone, Django, or Buildout, try to replicate the issue just using Pillow.
-->



--- 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/PIL/FitsImagePlugin.py`
Content:
```
1 #
2 # The Python Imaging Library
3 # $Id$
4 #
5 # FITS file handling
6 #
7 # Copyright (c) 1998-2003 by Fredrik Lundh
8 #
9 # See the README file for information on usage and redistribution.
10 #
11 
12 import math
13 
14 from . import Image, ImageFile
15 
16 
17 def _accept(prefix):
18     return prefix[:6] == b"SIMPLE"
19 
20 
21 class FitsImageFile(ImageFile.ImageFile):
22     format = "FITS"
23     format_description = "FITS"
24 
25     def _open(self):
26         headers = {}
27         while True:
28             header = self.fp.read(80)
29             if not header:
30                 msg = "Truncated FITS file"
31                 raise OSError(msg)
32             keyword = header[:8].strip()
33             if keyword == b"END":
34                 break
35             value = header[8:].strip()
36             if value.startswith(b"="):
37                 value = value[1:].strip()
38             if not headers and (not _accept(keyword) or value != b"T"):
39                 msg = "Not a FITS file"
40                 raise SyntaxError(msg)
41             headers[keyword] = value
42 
43         naxis = int(headers[b"NAXIS"])
44         if naxis == 0:
45             msg = "No image data"
46             raise ValueError(msg)
47         elif naxis == 1:
48             self._size = 1, int(headers[b"NAXIS1"])
49         else:
50             self._size = int(headers[b"NAXIS1"]), int(headers[b"NAXIS2"])
51 
52         number_of_bits = int(headers[b"BITPIX"])
53         if number_of_bits == 8:
54             self.mode = "L"
55         elif number_of_bits == 16:
56             self.mode = "I"
57             # rawmode = "I;16S"
58         elif number_of_bits == 32:
59             self.mode = "I"
60         elif number_of_bits in (-32, -64):
61             self.mode = "F"
62             # rawmode = "F" if number_of_bits == -32 else "F;64F"
63 
64         offset = math.ceil(self.fp.tell() / 2880) * 2880
65         self.tile = [("raw", (0, 0) + self.size, offset, (self.mode, 0, -1))]
66 
67 
68 # --------------------------------------------------------------------
69 # Registry
70 
71 Image.register_open(FitsImageFile.format, FitsImageFile, _accept)
72 
73 Image.register_extensions(FitsImageFile.format, [".fit", ".fits"])
74
```
--- 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/PIL/FitsImagePlugin.py b/src/PIL/FitsImagePlugin.py
--- a/src/PIL/FitsImagePlugin.py
+++ b/src/PIL/FitsImagePlugin.py
@@ -32,7 +32,7 @@
             keyword = header[:8].strip()
             if keyword == b"END":
                 break
-            value = header[8:].strip()
+            value = header[8:].split(b"/")[0].strip()
             if value.startswith(b"="):
                 value = value[1:].strip()
             if not headers and (not _accept(keyword) or value != b"T"):

{"golden_diff": "diff --git a/src/PIL/FitsImagePlugin.py b/src/PIL/FitsImagePlugin.py\n--- a/src/PIL/FitsImagePlugin.py\n+++ b/src/PIL/FitsImagePlugin.py\n@@ -32,7 +32,7 @@\n             keyword = header[:8].strip()\n             if keyword == b\"END\":\n                 break\n-            value = header[8:].strip()\n+            value = header[8:].split(b\"/\")[0].strip()\n             if value.startswith(b\"=\"):\n                 value = value[1:].strip()\n             if not headers and (not _accept(keyword) or value != b\"T\"):\n", "issue": "Cannot identify .fits file\n### What did you do?\r\nTried using pillow for opening/handling a .fits file for training a machine learning model. According to the documentation opening/reading fits files should be enabled? Or am I misunderstanding how a fits file should be opened? \r\n\r\n\r\nFrom Issue [4054](https://github.com/python-pillow/Pillow/issues/4054)/ PR 6056\r\n\r\n> I've created PR https://github.com/python-pillow/Pillow/pull/6056 to resolve this. If that is merged, you should no longer have to worry about register_handler(), but can instead just Image.open(\"sample.fits\").\r\n\r\n\r\n### What did you expect to happen?\r\nNot recieving a \"cannot identify error\" while using Image.open. Expected the function to work as with other supported file formats. The .fits files in question are not corrupted, and can be opened as normal with other software. \r\n\r\n### What happened?\r\n```python\r\nfrom PIL import Image\r\nwith Image.open('example.fits') as im:\r\n    im.verify()\r\n```\r\n\r\n```\r\n---------------------------------------------------------------------------\r\nUnidentifiedImageError                    Traceback (most recent call last)\r\nCell In [38], line 2\r\n      1 from PIL import FitsImagePlugin, ImageFile\r\n----> 2 with Image.open('example.fits') as im:\r\n      3     im.verify()\r\n\r\nFile ~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\PIL\\Image.py:3186, in open(fp, mode, formats)\r\n   3184 for message in accept_warnings:\r\n   3185     warnings.warn(message)\r\n-> 3186 raise UnidentifiedImageError(\r\n   3187     \"cannot identify image file %r\" % (filename if filename else fp)\r\n   3188 )\r\n\r\nUnidentifiedImageError: cannot identify image file 'example.fits'\r\n```\r\n### What are your OS, Python and Pillow versions?\r\n\r\n* OS: windows 10\r\n* Python: 3.10\r\n* Pillow: 9.3.0\r\n\r\n<!--\r\nPlease include **code** that reproduces the issue and whenever possible, an **image** that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.\r\n\r\nThe best reproductions are self-contained scripts with minimal dependencies. If you are using a framework such as Plone, Django, or Buildout, try to replicate the issue just using Pillow.\r\n-->\r\n\r\n\n", "before_files": [{"content": "#\n# The Python Imaging Library\n# $Id$\n#\n# FITS file handling\n#\n# Copyright (c) 1998-2003 by Fredrik Lundh\n#\n# See the README file for information on usage and redistribution.\n#\n\nimport math\n\nfrom . import Image, ImageFile\n\n\ndef _accept(prefix):\n    return prefix[:6] == b\"SIMPLE\"\n\n\nclass FitsImageFile(ImageFile.ImageFile):\n    format = \"FITS\"\n    format_description = \"FITS\"\n\n    def _open(self):\n        headers = {}\n        while True:\n            header = self.fp.read(80)\n            if not header:\n                msg = \"Truncated FITS file\"\n                raise OSError(msg)\n            keyword = header[:8].strip()\n            if keyword == b\"END\":\n                break\n            value = header[8:].strip()\n            if value.startswith(b\"=\"):\n                value = value[1:].strip()\n            if not headers and (not _accept(keyword) or value != b\"T\"):\n                msg = \"Not a FITS file\"\n                raise SyntaxError(msg)\n            headers[keyword] = value\n\n        naxis = int(headers[b\"NAXIS\"])\n        if naxis == 0:\n            msg = \"No image data\"\n            raise ValueError(msg)\n        elif naxis == 1:\n            self._size = 1, int(headers[b\"NAXIS1\"])\n        else:\n            self._size = int(headers[b\"NAXIS1\"]), int(headers[b\"NAXIS2\"])\n\n        number_of_bits = int(headers[b\"BITPIX\"])\n        if number_of_bits == 8:\n            self.mode = \"L\"\n        elif number_of_bits == 16:\n            self.mode = \"I\"\n            # rawmode = \"I;16S\"\n        elif number_of_bits == 32:\n            self.mode = \"I\"\n        elif number_of_bits in (-32, -64):\n            self.mode = \"F\"\n            # rawmode = \"F\" if number_of_bits == -32 else \"F;64F\"\n\n        offset = math.ceil(self.fp.tell() / 2880) * 2880\n        self.tile = [(\"raw\", (0, 0) + self.size, offset, (self.mode, 0, -1))]\n\n\n# --------------------------------------------------------------------\n# Registry\n\nImage.register_open(FitsImageFile.format, FitsImageFile, _accept)\n\nImage.register_extensions(FitsImageFile.format, [\".fit\", \".fits\"])\n", "path": "src/PIL/FitsImagePlugin.py"}], "after_files": [{"content": "#\n# The Python Imaging Library\n# $Id$\n#\n# FITS file handling\n#\n# Copyright (c) 1998-2003 by Fredrik Lundh\n#\n# See the README file for information on usage and redistribution.\n#\n\nimport math\n\nfrom . import Image, ImageFile\n\n\ndef _accept(prefix):\n    return prefix[:6] == b\"SIMPLE\"\n\n\nclass FitsImageFile(ImageFile.ImageFile):\n    format = \"FITS\"\n    format_description = \"FITS\"\n\n    def _open(self):\n        headers = {}\n        while True:\n            header = self.fp.read(80)\n            if not header:\n                msg = \"Truncated FITS file\"\n                raise OSError(msg)\n            keyword = header[:8].strip()\n            if keyword == b\"END\":\n                break\n            value = header[8:].split(b\"/\")[0].strip()\n            if value.startswith(b\"=\"):\n                value = value[1:].strip()\n            if not headers and (not _accept(keyword) or value != b\"T\"):\n                msg = \"Not a FITS file\"\n                raise SyntaxError(msg)\n            headers[keyword] = value\n\n        naxis = int(headers[b\"NAXIS\"])\n        if naxis == 0:\n            msg = \"No image data\"\n            raise ValueError(msg)\n        elif naxis == 1:\n            self._size = 1, int(headers[b\"NAXIS1\"])\n        else:\n            self._size = int(headers[b\"NAXIS1\"]), int(headers[b\"NAXIS2\"])\n\n        number_of_bits = int(headers[b\"BITPIX\"])\n        if number_of_bits == 8:\n            self.mode = \"L\"\n        elif number_of_bits == 16:\n            self.mode = \"I\"\n            # rawmode = \"I;16S\"\n        elif number_of_bits == 32:\n            self.mode = \"I\"\n        elif number_of_bits in (-32, -64):\n            self.mode = \"F\"\n            # rawmode = \"F\" if number_of_bits == -32 else \"F;64F\"\n\n        offset = math.ceil(self.fp.tell() / 2880) * 2880\n        self.tile = [(\"raw\", (0, 0) + self.size, offset, (self.mode, 0, -1))]\n\n\n# --------------------------------------------------------------------\n# Registry\n\nImage.register_open(FitsImageFile.format, FitsImageFile, _accept)\n\nImage.register_extensions(FitsImageFile.format, [\".fit\", \".fits\"])\n", "path": "src/PIL/FitsImagePlugin.py"}]}