Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 处理unicode_Python_Mediawiki Api - Fatal编程技术网

Python 处理unicode

Python 处理unicode,python,mediawiki-api,Python,Mediawiki Api,我是为runescape维基开发的。但是,每当我遇到unicode的问题时,让我们假设一个页面如下所示: This is a page, that has words To go here to there follow these directions: Backwards « Forwards That is all 如果只是执行mwhear.edit('Page over'),我将收到一个unicode错误 我尝试通过以下方式解决此问题: text = mwhair.edit('Page

我是为runescape维基开发的。但是,每当我遇到unicode的问题时,让我们假设一个页面如下所示:

This is a page, that has words
To go here to there follow these directions:
Backwards « Forwards
That is all
如果只是执行
mwhear.edit('Page over')
,我将收到一个unicode错误

我尝试通过以下方式解决此问题:

text = mwhair.edit('Page above').encode('ascii','xmlcharrefreplace')
mwhair.save('Page above',text=text)
这似乎是一个解决方案,因为不会出现错误,但会更改页面的某些内容,例如将行更改为:

Backwards « Forwards
这不会影响任何链接、图片或实际页面输出,但使bot看起来好像有错误。有什么事我搞砸了还是不知道?(我使用的是python 2.7.3)

在您的计算机上,您有:

'text':text,
text
在这一点上是Unicode,因此您可能希望在这一点上对其进行编码。
我假设MediaWiki想要UTF-8:

'text': text.encode('utf-8'),

这很有效,我知道这是少了一些小东西。谢谢