您正在使用Python 2运行为Python 3编写的代码。这将无法工作。
maketrans是
bytes内置类型的类方法,但 仅在Python 3中 。
# Python 3>>> bytes<class 'bytes'>>>> bytes.maketrans<built-in method maketrans of type object at 0x10aa6fe70>
在Python 2,
bytes是一个别名
str,但该类型并 没有 有方法:
# Python 2.7>>> bytes<type 'str'>>>> bytes.maketransTraceback (most recent call last): File "<stdin>", line 1, in <module>AttributeError: type object 'str' has no attribute 'maketrans'
而是使用Python 3运行您的代码,或将该项目中的所有代码转换为Python 2;后者需要深入了解Python 2和3的不同之处,这可能是一项重要的工作。
只是 翻译成Python 2的所示函数将是:
import stringimport urllib2import base64import randomdef get_appids(): fly = string.maketrans( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" ) f = urllib2.urlopen("http://lovejiani.com/v").read().translate(fly) d = base64.b64depre(f) e = unipre(d, encoding='ascii').split(u'rn') random.shuffle(e) return e


