TypeError:需要byteslike对象,而不是Python3.6.8中的“str”

2024-10-03 04:32:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手…我最近迁移到了py3.6.8。此代码在Python 2.7中正常工作:

#!/usr/bin/env python
from __future__ import print_function
import json
import sys
import os
import re
import subprocess
import datetime
from glob import glob
import boto3

class VariableCollector:
  def getall(self):
    collected_vars = {}
    for name in dir(self):
      #name = name.decode()
      if name.startswith("get_"):
        debug("VariableCollector - Calling: %s" % (name))
        method = getattr(self, name)
        collected_vars[name] = method()
        collected_vars[name + ":no_quotes"] = collected_vars[name].replace("'","")

        debug("Function: [%s] Value: [%s]" % ( name, collected_vars[name] ))
    return collected_vars

升级到3.6.8后,我得到:

  File "./process.py", line 21, in getall
    collected_vars[name + ":no_quotes"] = collected_vars[name].replace("'","")
TypeError: a bytes-like object is required, not 'str'

Tags: nonameinfromdebugimportselfvars