2012-11-18 153 views
2

我越來越即使所有的部件都是字符串蟒蛇類型的錯誤

request = str(self.SETUP) + " " + str(self.fileName) + "RTSP/1.0"; 
TypeError: unsupported operand type(s) for +: 'int' and 'str' 

整個代碼段下面的Python錯誤:

if requestCode == self.SETUP and self.state == self.INIT: 
    threading.Thread(target=self.recvRtspReply).start() 
    # Update RTSP sequence number. 
    self.rtspSeq = self.rtspSeq + 1 

    # Write the RTSP request to be sent. 
    request = str(self.SETUP) + " " + str(self.fileName) + "RTSP/1.0" 


    # Keep track of the sent request. 
    self.requestSent = request 
+5

我覺得你不會給我們整條線,最後以''來判斷。 – StoryTeller

+1

到目前爲止,我看到您顯示的內容沒有任何問題。有更多的線,或self.SETUP或self.filename屬性,觸發一些代碼?你確定這是引發異常的線嗎? – MikeHunter

+0

可能是一個奇怪的角落案例,但是你定義了一個名爲'str'的​​自己的函數來返回一個'int'嗎? – phimuemue

回答

0

試試這個:

if requestCode == self.SETUP and self.state == self.INIT: 
    threading.Thread(target=self.recvRtspReply).start() 
    # Update RTSP sequence number. 
    self.rtspSeq = int(self.rtspSeq) + 1 

    # Write the RTSP request to be sent. 
    rtps_req = "RTSP/1.0" 
    request = "%s %s %s" % (str(self.SETUP),str(self.fileName), rtps_req) 


    # Keep track of the sent request. 
    self.requestSent = request