Reputation: 8203
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.
Here's the code:
url = "http://www.myserver.com/prda.php?validate=" + licensey
readurl = br.open(url).read()
At the latter line, I get:
File "/usr/lib/python2.7/urllib.py", line 1038, in unwrap
url = url.strip()
AttributeError: 'QString' object has no attribute 'strip'
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()
Help?
Upvotes: 2
Views: 6797
Reputation: 1587
It is really strange that PyQt QString does not includes a strip() method, but it has a trimmed() method which does the same. See here: http://pyqt.sourceforge.net/Docs/PyQt4/qstring.html#trimmed. What are really lacking in PyQt are the variants lstrip() and rtrip().
Upvotes: 0
Reputation: 545
I guess you are developing a PyQt application and 'licensey' is a input you are taking from some 'QTextEdit' element.
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'.
Just add the line
url = str(url)
before calling the method open(url). Hope this helps :)
Upvotes: 4