python 类型错误

标签 python string int concatenation typeerror

<分区>

即使所有部分都是字符串,我仍收到以下 python 错误

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

整段代码:

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

最佳答案

试试这个:

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

关于 python 类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13445454/

相关文章:

python - 这个错误是什么意思 : invalid ELF header

python - 如何从文件创建二维字符列表?

java - 检查 List<Integer> 是否等于 int

string - 在 Swift 中将 Int 转换为 String

python - 为什么 DataFrame 列对于 json 转换必须是唯一的?

python - 在 python 中使用 networkx 计算无向图中大小为 k 的集团的最佳方法是什么?

c - 在 C 中重新分配字符串值

delphi - 在 Delphi 中将非定界文本转换为名称/值对

string - 从 f# 中的字符串中删除字符

java - 扫描仪输入匹配异常