2013-02-09 83 views
1

我在Django上使用haystack和solr。我得到了UnicodeDecodeError,我認爲原因是數據庫中的unicode數據要麼轉換爲str或者解碼爲utf-8,這會在通過httplib發送或打印到控制檯時導致稍後的UnicodeDecodeError。
我認爲這個問題應該在乾草堆full_prepare函數之前,因爲我後來檢查數據已經毀了。
有什麼想法?
我setup.pyed安裝(草堆,pysolr,django的) 和使用LXML的二進制從http://www.lfd.uci.edu/~gohlke/pythonlibs/Haystack UnicodeDecodeError

Microsoft Windows [Version 6.1.7601] 
Copyright (c) 2009 Microsoft Corporation. All rights reserved. 


C:\Users\Pouria\Desktop\conference\conference>python manage.py rebuild_index 

WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'. 
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command. 
Are you sure you wish to continue? [y/N] y 

Removing all documents from your index because you said so. 
Failed to clear Solr index: [Reason: Error 404 Not Found] 
All documents removed. 
C:\Python27\lib\site-packages\django\db\models\fields\__init__.py:808: RuntimeWarning: DateTimeField 
received a naive datetime (2013-02-09 08:47:27.110000) while time zone support is active. 
    RuntimeWarning) 
Indexing 2 conferences. 
ERROR:root:Error updating conferences using default 
Traceback (most recent call last): 
    File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\update_index.py", 
line 210, in handle_label 
    self.update_backend(label, using) 
    File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\update_index.py", 
line 256, in update_backend 
    do_update(backend, index, qs, start, end, total, self.verbosity) 
    File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\update_index.py", 
line 78, in do_update 
    backend.update(index, current_qs) 
    File "C:\Users\Pouria\Desktop\conference\conference\haystack\backends\solr_backend.py", line 72, i 
n update 
    self.conn.add(docs, commit=commit, boost=index.get_field_weights()) 
    File "C:\Python27\lib\site-packages\pysolr.py", line 786, in add 
    return self._update(m, commit=commit, waitFlush=waitFlush, waitSearcher=waitSearcher) 
    File "C:\Python27\lib\site-packages\pysolr.py", line 379, in _update 
    return self._send_request('post', path, message, {'Content-type': 'text/xml; charset=utf-8'}) 
    File "C:\Python27\lib\site-packages\pysolr.py", line 291, in _send_request 
    timeout=self.timeout) 
    File "C:\Python27\lib\site-packages\requests\api.py", line 87, in post 
    return request('post', url, data=data, **kwargs) 
    File "C:\Python27\lib\site-packages\requests\api.py", line 44, in request 
    return session.request(method=method, url=url, **kwargs) 
    File "C:\Python27\lib\site-packages\requests\sessions.py", line 279, in request 
    resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies 
) 
    File "C:\Python27\lib\site-packages\requests\sessions.py", line 373, in send 
    r = adapter.send(request, **kwargs) 
    File "C:\Python27\lib\site-packages\requests\adapters.py", line 171, in send 
    timeout=timeout 
    File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 421, in url 
open 
    body=body, headers=headers) 
    File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 273, in _ma 
ke_request 
    conn.request(method, url, **httplib_request_kw) 
    File "C:\Python27\lib\httplib.py", line 949, in request 
    self._send_request(method, url, body, headers) 
    File "C:\Python27\lib\httplib.py", line 990, in _send_request 
    self.endheaders(body) 
    File "C:\Python27\lib\httplib.py", line 943, in endheaders 
    self._send_output(message_body) 
    File "C:\Python27\lib\httplib.py", line 810, in _send_output 
    self.send(message_body) 
    File "C:\Python27\lib\httplib.py", line 775, in send 
    self.sock.sendall(str) 
    File "C:\Python27\lib\socket.py", line 222, in meth 
    return getattr(self._sock,name)(*args) 
UnicodeEncodeError: 'ascii' codec can't encode characters in position 143-149: ordinal not in range(
128) 
Traceback (most recent call last): 
    File "manage.py", line 10, in <module> 
    execute_from_command_line(sys.argv) 
    File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 443, in execute_from 
_command_line 
    utility.execute() 
    File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 382, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "C:\Python27\lib\site-packages\django\core\management\base.py", line 196, in run_from_argv 
    self.execute(*args, **options.__dict__) 
    File "C:\Python27\lib\site-packages\django\core\management\base.py", line 232, in execute 
    output = self.handle(*args, **options) 
    File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\rebuild_index.py" 
, line 15, in handle 
    call_command('update_index', **options) 
    File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 150, in call_command 

    return klass.execute(*args, **defaults) 
    File "C:\Python27\lib\site-packages\django\core\management\base.py", line 232, in execute 
    output = self.handle(*args, **options) 
    File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\update_index.py", 
line 184, in handle 
    return super(Command, self).handle(*items, **options) 
    File "C:\Python27\lib\site-packages\django\core\management\base.py", line 341, in handle 
    label_output = self.handle_label(label, **options) 
    File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\update_index.py", 
line 210, in handle_label 
    self.update_backend(label, using) 
    File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\update_index.py", 
line 256, in update_backend 
    do_update(backend, index, qs, start, end, total, self.verbosity) 
    File "C:\Users\Pouria\Desktop\conference\conference\haystack\management\commands\update_index.py", 
line 78, in do_update 
    backend.update(index, current_qs) 
    File "C:\Users\Pouria\Desktop\conference\conference\haystack\backends\solr_backend.py", line 72, i 
n update 
    self.conn.add(docs, commit=commit, boost=index.get_field_weights()) 
    File "C:\Python27\lib\site-packages\pysolr.py", line 786, in add 
    return self._update(m, commit=commit, waitFlush=waitFlush, waitSearcher=waitSearcher) 
    File "C:\Python27\lib\site-packages\pysolr.py", line 379, in _update 
    return self._send_request('post', path, message, {'Content-type': 'text/xml; charset=utf-8'}) 
    File "C:\Python27\lib\site-packages\pysolr.py", line 291, in _send_request 
    timeout=self.timeout) 
    File "C:\Python27\lib\site-packages\requests\api.py", line 87, in post 
    return request('post', url, data=data, **kwargs) 
    File "C:\Python27\lib\site-packages\requests\api.py", line 44, in request 
    return session.request(method=method, url=url, **kwargs) 
    File "C:\Python27\lib\site-packages\requests\sessions.py", line 279, in request 
    resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies 
) 
    File "C:\Python27\lib\site-packages\requests\sessions.py", line 373, in send 
    r = adapter.send(request, **kwargs) 
    File "C:\Python27\lib\site-packages\requests\adapters.py", line 171, in send 
    timeout=timeout 
    File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 421, in url 
open 
    body=body, headers=headers) 
    File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 273, in _ma 
ke_request 
    conn.request(method, url, **httplib_request_kw) 
    File "C:\Python27\lib\httplib.py", line 949, in request 
    self._send_request(method, url, body, headers) 
    File "C:\Python27\lib\httplib.py", line 990, in _send_request 
    self.endheaders(body) 
    File "C:\Python27\lib\httplib.py", line 943, in endheaders 
    self._send_output(message_body) 
    File "C:\Python27\lib\httplib.py", line 810, in _send_output 
    self.send(message_body) 
    File "C:\Python27\lib\httplib.py", line 775, in send 
    self.sock.sendall(str) 
    File "C:\Python27\lib\socket.py", line 222, in meth 
    return getattr(self._sock,name)(*args) 
UnicodeEncodeError: 'ascii' codec can't encode characters in position 143-149: ordinal not in range(
128) 

回答