Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8329321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:44:34+00:00 2026-06-09T01:44:34+00:00

I keep receiving the TypeError: coercing to Unicode: need string or buffer, bool found

  • 0

I keep receiving the “TypeError: coercing to Unicode: need string or buffer, bool found” when reading the filename in my code. I can’t seem to figure it out, as I expressly use filename=str(“QFileDialog…..”)… where am I going wrong?

class MainWindow(QMainWindow):
    def __init__(self, filename=None, parent=None):
        super(MainWindow,self).__init__(parent)

        self.fileheader=None
        self.frameheader = None

        self.initUI()
        self.resize(900,900)


        if filename:
            self.setDataFile(filename)



    def initUI(self):
        self.filetable=QTableWidget()

        self.frametable=QTableWidget()
        self.filetable.setEditTriggers(self.filetable.NoEditTriggers)
        self.frametable.setEditTriggers(self.filetable.NoEditTriggers)

        self.imageBrowser=ImageViewer()

        self.imagesplitter=QSplitter(Qt.Horizontal)
        self.tablesplitter=QSplitter(Qt.Horizontal)
        self.imagesplitter.addWidget(self.imageBrowser)
        self.tablesplitter.addWidget(self.imagesplitter)
        self.tablesplitter.addWidget(self.filetable)
        self.tablesplitter.addWidget(self.frametable)
        self.setCentralWidget(self.tablesplitter)

        self._setTables()
        self._createMenuBar()

        self.imageBrowser.slider.sliderMoved.connect(self.change_image_index)


    def _setTables(self):

        self.filetable.setRowCount(len(FileHeader.fileheader_fields))
        self.filetable.setColumnCount(2)
        self.filetable.setHorizontalHeaderLabels(['File Header','value'])
        for i,field in enumerate(FileHeader.fileheader_fields):
            # just set the field names...no data
            name=QTableWidgetItem(field)
            #value=QTableWidgetItem(unicode(getattr(self.fileheader,field)))
            self.filetable.setItem(i,0,name)
            #self.filetable.setItem(i,1,value)

        #self.frameheader=self.fileheader.frameAtIndex(0)
        self.frametable.setRowCount(len(Frame.frameheader_fields))
        self.frametable.setColumnCount(2)
        self.frametable.setHorizontalHeaderLabels(['Frame Header','Value'])
        for i,fields in enumerate(Frame.frameheader_fields):
            # name only...no data yet
            Name=QTableWidgetItem(fields)
            #Value=QTableWidgetItem(unicode(getattr(self.frameheader,fields)))
            self.frametable.setItem(i,0,Name)

    def _createMenuBar(self):

        menubar=self.menuBar()

        exitAction=QAction(QIcon('exit.png'),'&Exit',self)
        exitAction.setShortcut('Ctrl+Q')
        exitAction.triggered.connect(qApp.quit)

        openAction=QAction(QIcon('open.png'),'&Open',self)
        openAction.setShortcut('Ctrl+O')
        openAction.triggered.connect(self.openNewFile)
        openAction.triggered.connect(self.setDataFile)

        fileMenu=menubar.addMenu('&File')
        fileMenu.addAction(openAction)
        fileMenu.addAction(exitAction)



    def populate(self):
        if not self.frameheader:
            print "[DEBUG] populate(): self.frameheader is None"
            return

        for i,field in enumerate(FileHeader.fileheader_fields):
            name=QTableWidgetItem(field)
            value=QTableWidgetItem(unicode(getattr(self.fileheader,field)))
            self.filetable.setItem(i,0,name)
            self.filetable.setItem(i,1,value)

        #self.frametable.setRowCount(len(self.frameheader.frameheader_fields))
        #self.frametable.setColumnCount(2)
        #self.frametable.setHorizontalHeaderLabels(['Frame Header','Value'])
        for i,fields in enumerate(self.frameheader.frameheader_fields):
            Name=QTableWidgetItem(fields)
            Value=QTableWidgetItem(unicode(getattr(self.frameheader,fields)))
            self.frametable.setItem(i,0,Name)
            self.frametable.setItem(i,1,Value)

    def change_image_index(self,val):
        if not self.fileheader:
            print "[DEBUG] change_image_index(): self.fileheader is None"
            return

        self.frameheader=self.fileheader.frameAtIndex(val)
        self.populate()

    def setDataFile(self, filename):
        self.fileheader=FileHeader(filename)
        self.imageBrowser.setFileHeader(self.fileheader)
        #frame=Frame(filename) # you only need the frame on demand

        self.change_image_index(0)


    def openNewFile(self):
        filename=str(QFileDialog.getOpenFileName(None,"open file","C:/vprice/DIDSON/DIDSON Data","*.ddf"))
        self.setDataFile(filename)



if __name__=="__main__":
    app=QApplication([])
    w=MainWindow()
    w.show()
    w.raise_()
    app.exec_()

and the error code:

Traceback (most recent call last):
  File "C:\Users\Tory\Desktop\PYTHON NOAA\DIDSONGUIqwttest.py", line 197, in setDataFile
    self.fileheader=FileHeader(filename)
  File "C:\Python27\lib\fileheader.py", line 31, in __init__
    self.infile=open(filename,'rb')
TypeError: coercing to Unicode: need string or buffer, bool found
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:44:37+00:00Added an answer on June 9, 2026 at 1:44 am

    The source of the problem is here:

    openAction.triggered.connect(self.openNewFile)
    openAction.triggered.connect(self.setDataFile)
    

    Did you really mean to connect the openAction to setDataFile as well?

    Note that the signature for the triggered signal is:

    void QAction::triggered ( bool checked = false ) [signal]
    

    This means that the setDataFile method keeps getting called with its filename argument set to False – and explains why you are seeing the TypeError complaining about receiving a boolean instead of a string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The error that I keep on receiving when running a regression uite, can someone
I can't seem to find the proper audio source for recording/analyzing/receiving the currently played
I can't find out what the problem is, and why I keep receiving this
I keep on receiving odd unexpected values for my bool testValue . I keep
I'm new to javascript/jquery. I have the following basic code and I keep receiving
I keep receiving the error LINQ to Entities does not recognize the method 'System.String
I keep receiving this error... [2012-06-14 11:54:50,072: ERROR/MainProcess] Hard time limit (300s) exceeded for
I'm trying to implement my own GenericIdentity implementation but keep receiving the following error
I've just lauched a HTML5 game application, and I keep receiving ' object doesn't
I'm trying to mock MouseButtonEventArgs.GetPosition() with Moq, but I keep receiving this error: System.ArgumentException:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.