'QString' 对象没有属性 'strip'? [英] 'QString' object has no attribute 'strip'?

查看:46
本文介绍了'QString' 对象没有属性 'strip'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试使用 Python 中的 mechanize.Browser() 模块读取网页.问题是 br.open(url) 不起作用,因为python返回标题中的错误.

So I'm trying to read a web page using mechanize.Browser() module in Python. The problem is that br.open(url) does not work, because python returns the error in the title.

代码如下:

url = "http://www.myserver.com/prda.php?validate=" + licensey
readurl = br.open(url).read()

在后一行,我得到:

File "/usr/lib/python2.7/urllib.py", line 1038, in unwrap
url = url.strip()
AttributeError: 'QString' object has no attribute 'strip'

我尝试使用 unicode(readurl)、unicode (br.open(url).read())、readlines() 代替 read()、str(代替 unicode)...我要么得到同样的错误, 或 br.open.read() 的无输出

I tried using unicode(readurl), unicode (br.open(url).read()), readlines() instead of read(), str (in place of unicode)... I either get the same error, or None output from br.open.read()

帮助?

推荐答案

我猜您正在开发 PyQt 应用程序,而licensey"是您从某个QTextEdit"元素中获取的输入.

I guess you are developing a PyQt application and 'licensey' is a input you are taking from some 'QTextEdit' element.

在您的应用程序中,url"的类型为QString".并且在QString"数据类型中没有strip"方法.由于 open() 方法期望您发送类型为str"的参数,因此您只需要对变量url"进行类型转换.

In your application the 'url' is of type 'QString'. And there is no 'strip' method in 'QString' data type. Since open() method expects you to send a parameter of type 'str', you just need to typecast the variable 'url'.

只需添加一行

url = str(url)

在调用方法 open(url) 之前.希望这会有所帮助:)

before calling the method open(url). Hope this helps :)

这篇关于'QString' 对象没有属性 'strip'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆