如何在Python中解决此错误?

mdcn47

我知道这将被标记为重复帖子,因为对此错误存在一些疑问。我已经解决了这些问题,但不知道如何解决。请帮我。这是错误消息。

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1489, in __call__
    return self.func(*args)
  File "iptrace.py", line 21, in mbt
    tkMessageBox.showinfo(tget, tget+" lives in "+jd["city"]+", "+jd["region"]+" "+jd["country"])
TypeError: cannot concatenate 'str' and 'NoneType' objects

这是代码:

from Tkinter import *
import tkMessageBox
import json
import urllib
import sys

def wmi():
    uip = urllib.urlopen("http://www.networksecuritytoolkit.org/nst/tools/ip.php").read()
    tkMessageBox.showinfo("Whats my IP", "Your IP is "+uip)
def mbt():

    global ew1

    tget = ew1.get().strip()

    jd = json.load(urllib.urlopen("http://ipinfo.io/"+tget+"/geo"))

    if tget == "":
      tkMessageBox.showerror(tget, "Type a IP Please")
    else:
      tkMessageBox.showinfo(tget, tget+" lives in "+jd["city"]+", "+jd["region"]+" "+jd["country"]) 

if __name__ == "__main__":

    root = Tk()

    root.title("-|IP2Location|-")

    textFrame = Frame(root)

    entryLabel = Label(textFrame)
    entryLabel["text"] = "IP :"
    entryLabel.pack(side=LEFT)

    ew1 = Entry(textFrame)
    ew1["width"] = 24
    ew1.pack(side=LEFT)

    textFrame.pack()

    bmi = Button(root, text="Whats my IP", command=wmi)
    bmi.pack()

    bs = Button(root, text="Submit", command=mbt)
    bs.pack()

    def enterPress(event):
      mbt()

    root.bind("<Return>", enterPress)

    def enterPress(event):
      exit()
      sys.exit(0)

    root.bind("<Escape>", enterPress)
    root.mainloop() 
勒布

如回溯中所述,该错误位于:

else:
      tkMessageBox.showinfo(tget, tget+" lives in \
          "+jd["city"]+", "+jd["region"]+" "+jd["country"])

因此,导致问题的原因是您将+符号用于两种不同的类型,一种是a string,另一种是NoneType(即没有值)。

因此,您需要使用str(var)要在该语句内连接的字符串将预定义变量更改为字符串只有这样,它才能毫无问题地运行。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在html搜索模板中解决此错误?

来自分类Dev

如何在ChueckSUR.log中解决此清单错误?

来自分类Dev

如何解决python django中的此错误?

来自分类Dev

如何解决python django中的此错误?

来自分类Dev

如何在Weka上解决此错误?

来自分类Dev

在MiniZinc中如何解决此错误?

来自分类Dev

此查询中的错误:如何解决?

来自分类Dev

如何在C中解决此输出?

来自分类Dev

如何在Perl中解决此警告

来自分类Dev

如何在C中解决此输出?

来自分类Dev

如何在JSP中解决此代码?

来自分类Dev

如何在Angular应用程序中解决此错误“ ControlContainerAngular没有提供者”

来自分类Dev

如何在MySQL中创建虚拟表来解决此错误?

来自分类Dev

如何在Bukkit /插件编程中解决此错误:java:找不到符号构造函数CommandExecute()

来自分类Dev

如何在mysql中加载数据来解决此错误?

来自分类Dev

如何在登录页面上解决此设计错误?

来自分类Dev

如何在命令行上解决此新错误?

来自分类Dev

如何在Python中编写此C for循环?-最好的解决方案是什么?

来自分类Dev

如何解决此错误?

来自分类Dev

如何解决此错误?

来自分类Dev

如何解决此错误?

来自分类Dev

如何在Java中修复此错误?

来自分类Dev

如何在MFC中更正此错误?

来自分类Dev

如何解决此Python elif语句语法错误?

来自分类Dev

如何解决Java 8中的此错误?

来自分类Dev

如何解决Odoo-8中的此错误?

来自分类Dev

如何解决numpy中的此MemoryView错误?

来自分类Dev

如何解决pdfquery中的此追溯错误

来自分类Dev

如何解决此DirectX代码中的错误?