为了自动能从群里采集数据,并提及到share.idoubi.net(全球资源逗分享)上,我用python写了爬虫,但是只从将wordpress更新自6.0版本后,在使用python登录wordpres时就报错:xml.parsers.expat.ExpatError: XML or text declaration not at start of entity
错误提示:
Traceback (most recent call last): File "F:/Dropbox/python/django/wp/post.py", line 49, in <module> p = PostArticle() File "F:/Dropbox/python/django/wp/post.py", line 15, in __init__ self.wp = Client(url='{}/xmlrpc.php'.format(URL), username=USERNAME, password=PASSWORD) File "D:\software\python35\lib\site-packages\wordpress_xmlrpc\base.py", line 24, in __init__ self.supported_methods = self.server.mt.supportedMethods() File "D:\software\python35\lib\xmlrpc\client.py", line 1092, in __call__ return self.__send(self.__name, args) File "D:\software\python35\lib\xmlrpc\client.py", line 1432, in __request verbose=self.__verbose File "D:\software\python35\lib\xmlrpc\client.py", line 1134, in request return self.single_request(host, handler, request_body, verbose) File "D:\software\python35\lib\xmlrpc\client.py", line 1150, in single_request return self.parse_response(resp) File "D:\software\python35\lib\xmlrpc\client.py", line 1316, in parse_response p.feed(data) File "D:\software\python35\lib\xmlrpc\client.py", line 438, in feed self._parser.Parse(data, 0) xml.parsers.expat.ExpatError: XML or text declaration not at start of entity: line 2, column 0
解决方法:
1. 找到python安装路径,如我的:D:\software\python35\
2. 进入路径:Lib\xmlrpc,完整路径:D:\software\python35\Lib\xmlrpc
3. 打开client.py文件。
原代码:
def feed(self, data): self._parser.Parse(data, 0)
改成如下的代码:
def feed(self, data): self._parser.Parse(data.strip(), 0)
- 本文固定链接: http://jingyan.idoubi.net/5173.html
- 转载请注明: 游戏创作者大陆 于 逗分享开发经验 发表