[PyQt] Issues with PyQt and xmlrpclib

Albert Cervera i Areny albert at nan-tic.com
Sun Oct 26 09:31:45 GMT 2008


A Diumenge 26 Octubre 2008, D. Can Celasun va escriure:
> Hello,
>
> I'm using this wordpress library for Python (
> http://www.blackbirdblog.it/programmazione/progetti/28#english). When I use
> it through the Python shell, or any other program, it runs just fine.
> However when I use it through the GUI I've prepared it gives the following
> error:
>
> Traceback (most recent call last):
>   File "project.py", line 230, in postWordpress
>     wp = wordpresslib.WordPressClient(wordpress, username, password)
>   File "/home/dcelasun/pyqt/proje/wordpresslib.py", line 129, in __init__
>     self._server = xmlrpclib.ServerProxy(self.url)
>   File "/usr/lib/python2.5/xmlrpclib.py", line 1409, in __init__
>     type, uri = urllib.splittype(uri)
>   File "/usr/lib/python2.5/urllib.py", line 1023, in splittype
>     match = _typeprog.match(url)
> TypeError: buffer size mismatch
>
>
> I've googled for quite some time but couldn't find anything. Here's the
> function that does the actual work. Again, the following works in the
> shell, but gives the above error with PyQt
>
>     def postWordpress(self):
>         wordpress = ui.lineEdit.text()
>         username = ui.lineEdit_2.text()
>         password = ui.lineEdit_3.text()
>
>         post_title = ui.lineEdit_4.text()
>         post_body = ui.textEdit.toPlainText()
>
>         # prepare client object
>         wp = wordpresslib.WordPressClient(wordpress, username, password)
>
>         # select blog id
>         wp.selectBlog(0)
>
>         # create post object
>         post = wordpresslib.WordPressPost()
>         post.title = post_title
>         post.description = post_body
>
>         # publish post
>         idNewPost = wp.newPost(post, True)
>         ui.label_12.setText("Your post is successfully published!")

The problem is that you should convert QString's into unicode or str strings 
to send them with XML-RPC. Use something like this:


def postWordpress(self):
        wordpress = unicode(ui.lineEdit.text())
        username = unicode(ui.lineEdit_2.text())
        password = unicode(ui.lineEdit_3.text())

        post_title = unicode(ui.lineEdit_4.text())
        post_body = unicode(ui.textEdit.toPlainText())

        # prepare client object
        wp = wordpresslib.WordPressClient(wordpress, username, password)

        # select blog id
        wp.selectBlog(0)

        # create post object
        post = wordpresslib.WordPressPost()
        post.title = post_title
        post.description = post_body

        # publish post
        idNewPost = wp.newPost(post, True)
        ui.label_12.setText("Your post is successfully published!")


>
>
> What do you think is wrong?
>
> Thanks,
> Can



-- 
Albert Cervera i Areny
http://www.NaN-tic.com


More information about the PyQt mailing list