TypeError:无法将返回值转换为所需类型

时间:2015-02-23 18:13:57

标签: python-3.x webkit

当我运行我的python脚本时,我得到以下控制台输出:

TypeError: can't convert return value to desired type

脚本执行我的操作除外,我不知道此消息的来源。如何确定哪一行包含触发消息的代码以隔离原因?

修改

一个最小的例子:

#!/usr/bin/python
import gi
import os
import urllib
import urllib.parse
import getopt
import sys
from gi.repository import Gtk,WebKit

#resolve the file url
fileUri = 'test.html'
fileUri = os.path.realpath(fileUri)
fileUri = urllib.parse.ParseResult('file', '', fileUri, '', '', '')
fileUri = urllib.parse.urlunparse(fileUri)

def navrequest(thisview, frame, networkRequest):
    address = networkRequest.get_uri()

    if not fileUri in address:
        md = Gtk.MessageDialog(win,0,Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE, "Not allowed to leave the site!")

        md.run()
        md.destroy()
        view.open(fileUri)

view = WebKit.WebView()
view.connect("navigation-requested", navrequest)

sw = Gtk.ScrolledWindow()
sw.add(view)

vbox = Gtk.VBox()
vbox.add(sw)

win = Gtk.Window()
win.set_size_request(800, 600)
win.connect("destroy", Gtk.main_quit)
win.set_title("TypeErrortest")
win.add(vbox)
win.show_all()

view.open(fileUri) 
Gtk.main()

test.hmtml:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title of the document</title>
</head>
<body>
    <h1>Test</h1>
</body>
</html>

完整的控制台输出:

[me ~]$ ./testTypeError.py 
TypeError: can't convert return value to desired type
[me ~]$

操作系统:Arch Linux

版本:Python 3.4.2

1 个答案:

答案 0 :(得分:1)

处理信号的函数的返回值是问题。将return 0添加到navrequest函数会使消息消失。