您正在运行使用Python 2为Python 3编写的代码.这不起作用.
maketrans是字节内置类型的类方法,但仅限于Python 3.
# Python 3
>>> bytes
>>> bytes.maketrans
在Python 2中,bytes是str的别名,但该类型没有该方法:
# Python 2.7
>>> bytes
>>> bytes.maketrans
Traceback (most recent call last):
File "", line 1, in
AttributeError: type object 'str' has no attribute 'maketrans'
用Python 3运行你的代码,或者将这个项目中的所有代码翻译成Python 2;后者需要深入了解Python 2和3的不同之处,并且可能是一项重大任务.
只是说明的函数,翻译成Python 2,将是:
import string
import urllib2
import base64
import random
def get_appids():
fly = string.maketrans(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM"
)
f = urllib2.urlopen("http://lovejiani.com/v").read().translate(fly)
d = base64.b64decode(f)
e = unicode(d, encoding='ascii').split(u'
')
random.shuffle(e)
return e