diff --git a/CEP/PyBDSM/src/python/functions.py b/CEP/PyBDSM/src/python/functions.py
index d81fc8d42b02fdfb43b6df92e65cc4d8194b23d0..b3769185543dd21f7127523c1a42f56cf3232159 100755
--- a/CEP/PyBDSM/src/python/functions.py
+++ b/CEP/PyBDSM/src/python/functions.py
@@ -1182,8 +1182,8 @@ def convert_pyrap_header(pyrap_image):
     import pyfits
 
     tfile = tempfile.NamedTemporaryFile(delete=False)
-    pyrap_image.tofits(tfile)
-    hdr = pyfits.get_header(tfile)
+    pyrap_image.tofits(tfile.name)
+    hdr = pyfits.get_header(tfile.name)
     return hdr