好的,我正在尝试在跟踪器中获取人员和时间戳,但我一直收到此错误:
invalid literal for int() with base 10: 1389584370.27156
这是获取该错误的代码:
elif used_prefix and cmd == "tracker" and self.getAccess(user) >= 1:
try:
if len(args) == 0:
name = user.name.lower()
elif len(args) > 0:
name = args.lower()
f = urlreq.urlopen("http://chtracker.info/index.py?output=json&x=page&y={}".format(name))
data = json.loads(f.readall().decode("utf-8"))
t = "{}, the last 10 people who visited {}'s profile are: ".format(name.title(), name.title())
viewers = [(item['viewer'], item['timestamp']) for item in data]
for l in viewers:
viewer, timest = l
t += "{} about {} ago".format(viewer, stamp.getTimeStamp(timest))
room.message(t, True)
except:
print(traceback.format_exc())
room.message((str(sys.exc_info()[1])))
错误发生在这一行:
t += "{} about {} ago".format(viewer, stamp.getTimeStamp(timest))
回溯来自timestamp2.py行:
Traceback (most recent call last): File "G:\Bots\Dragion Bot\Dragion Bot.Py", line 1159, in onMessage t += "{} about {} ago".format(viewer, stamp.getTimeStamp(timest)) File "G:\Bots\Dragion Bot\timestamp2.py", line 6, in getTimeStamp if int(t) <= time.time(): ValueError: invalid literal for int() with base 10: '1389584370.27156'
在网址中,dictionarys具有相同的标签“viewer”和“timestamp”,例如:
http://chtracker.info/index.py?output=json&x=page&y=mechabot
答案 0 :(得分:2)
if int(t) <= time.time()
不要在不表示整数的字符串上调用int
。如果字符串应该表示一个有效的整数,那么输入有问题。如果允许字符串具有小数部分,与您显示的输入一样,则不要使用int
。 float
可能是合适的。