' NoneType'对象没有属性' rstrip'草垛

时间:2015-05-20 12:04:48

标签: django django-haystack pysolr

我正在使用haystack后端solr。 我收到一个奇怪的错误' NoneType'对象没有属性' rstrip' 我已多次更新我的索引,检查版本等等但没有任何效果。

这是我的SearchIndex文件:

class JobIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    post_type = indexes.CharField(model_attr='post_type',faceted=True)
    job_location = indexes.CharField(model_attr='job_location',faceted=True,null=True)
    #job_type = indexes.CharField(model_attr='job_type',faceted=True,null=True)
    company_name = indexes.CharField(model_attr='company_name',faceted=True)
    hide_company_name=indexes.BooleanField(model_attr='hide_company_name', default='false')
    hot_job = indexes.BooleanField(model_attr='hot_job', default='false')
    how_to_apply_check = indexes.CharField(model_attr='how_to_apply_check')
    how_to_apply= indexes.CharField(model_attr='how_to_apply')
    job_title = indexes.CharField(model_attr='job_title', faceted=True, boost=1.5)
    start_date = indexes.DateField(model_attr='start_date', faceted=True,null=True)
    end_date = indexes.DateField(model_attr='end_date', faceted=True,null=True)
    job_description = indexes.CharField(model_attr='job_description', faceted=False)
    country = indexes.CharField(model_attr='country', faceted=True,null=True)
    is_online = indexes.CharField(model_attr='is_online', null=True)
    industry_id = indexes.CharField(model_attr='industry_id',faceted=True,null=True)
    functional_area_id = indexes.CharField(model_attr='functional_area_id',faceted=True,null=True)
    content_auto = indexes.EdgeNgramField(model_attr='job_title')
    content_location = indexes.EdgeNgramField(model_attr='job_location')
    creation_time = indexes.DateTimeField(model_attr='creation_time')

    def get_model(self):
        return jobpost

    def prepare(self, obj):
        data = super(JobIndex, self).prepare(obj)
        data['boost'] = 1.1
        return data

    def prepare_company_name(self, obj):
        if obj.hide_company_name:
            return "Confidential"
        else:
            return obj.company_name

    def index_queryset(self,**kwargs):
        return self.get_model().objects.all()

    def prepare_job_location(self, obj):
        #return [obj.user_id for obj in obj.users.all()]
        return (obj.job_location.strip())

    def get_updated_field(self):
        return 'updated'

和日志:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/haystack/views.py", line 50, in __call__
    return self.create_response()
  File "/usr/local/lib/python2.7/dist-packages/haystack/views.py", line 130, in create_response
    (paginator, page) = self.build_page()
  File "/usr/local/lib/python2.7/dist-packages/haystack/views.py", line 107, in build_page
    self.results[start_offset:start_offset + self.results_per_page]
  File "/usr/local/lib/python2.7/dist-packages/haystack/query.py", line 268, in __getitem__
    self._fill_cache(start, bound)
  File "/usr/local/lib/python2.7/dist-packages/haystack/query.py", line 166, in _fill_cache
    results = self.query.get_results(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/haystack/backends/__init__.py", line 644, in get_results
    self.run(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/haystack/backends/solr_backend.py", line 693, in run
    results = self.backend.search(final_query, **search_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/haystack/backends/__init__.py", line 34, in wrapper
    return func(obj, query_string, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/haystack/backends/solr_backend.py", line 125, in search
    raw_results = self.conn.search(query_string, **search_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pysolr-3.1.0-py2.7.egg/pysolr.py", line 606, in search
    response = self._select(params)
  File "/usr/local/lib/python2.7/dist-packages/pysolr-3.1.0-py2.7.egg/pysolr.py", line 343, in _select
    return self._send_request('post', path, body=params_encoded, headers=headers)
  File "/usr/local/lib/python2.7/dist-packages/pysolr-3.1.0-py2.7.egg/pysolr.py", line 272, in _send_request
    url = self._create_full_url(path)
  File "/usr/local/lib/python2.7/dist-packages/pysolr-3.1.0-py2.7.egg/pysolr.py", line 266, in _create_full_url
    return '/'.join([self.url.rstrip('/'), path.lstrip('/')])
AttributeError: 'NoneType' object has no attribute 'rstrip'

有人可以帮我解决这个问题吗

1 个答案:

答案 0 :(得分:0)

从堆栈跟踪看起来,未定义self.url,这会导致pysolr抛出拟合。检查haystack配置文件是否为Solr设置了正确的URL。