问题描述
我最初的问题是models not loaded yet
并以某种方式从stackoverflow获得了django.setup()
解决了该问题的信息。
但是再一次,当我使用django.setup()
我得到了这个错误:
ValueError: invalid literal for int() with base 10
这是我的回溯
Traceback (most recent call last):
File "C:/Users/Samson/Documents/searchengine/SearchEngine/Scripts/lens/lens/crawler.py", line 110, in <module>
spider.crawl_web()
File "C:/Users/Samson/Documents/searchengine/SearchEngine/Scripts/lens/lens/crawler.py", line 66, in crawl_web
objListing.save() #save to database
File "C:\Python27\Lib\site-packages\django\db\models\base.py", line 591, in save
force_update=force_update, update_fields=update_fields)
File "C:\Python27\Lib\site-packages\django\db\models\base.py", line 619, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "C:\Python27\Lib\site-packages\django\db\models\base.py", line 681, in _save_table
forced_update)
File "C:\Python27\Lib\site-packages\django\db\models\base.py", line 711, in _do_update
filtered = base_qs.filter(pk=pk_val)
File "C:\Python27\Lib\site-packages\django\db\models\query.py", line 691, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\Lib\site-packages\django\db\models\query.py", line 709, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\Lib\site-packages\django\db\models\sql\query.py", line 1287, in add_q
clause, require_inner = self._add_q(where_part, self.used_aliases)
File "C:\Python27\Lib\site-packages\django\db\models\sql\query.py", line 1314, in _add_q
current_negated=current_negated, connector=connector)
File "C:\Python27\Lib\site-packages\django\db\models\sql\query.py", line 1186, in build_filter
condition = self.build_lookup(lookups, col, value)
File "C:\Python27\Lib\site-packages\django\db\models\sql\query.py", line 1094, in build_lookup
return final_lookup(lhs, rhs)
File "C:\Python27\Lib\site-packages\django\db\models\lookups.py", line 82, in __init__
self.rhs = self.get_prep_lookup()
File "C:\Python27\Lib\site-packages\django\db\models\lookups.py", line 85, in get_prep_lookup
return self.lhs.output_field.get_prep_lookup(self.lookup_name, self.rhs)
File "C:\Python27\Lib\site-packages\django\db\models\fields\__init__.py", line 646, in get_prep_lookup
return self.get_prep_value(value)
File "C:\Python27\Lib\site-packages\django\db\models\fields\__init__.py", line 915, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: '5617c8f4b705960e4c314406'
Process finished with exit code 1
谢谢
1楼
这与django.setup()
没有关系。
错误发生在crawl_web
:您正在尝试保存带有整数字段的项目,但给它提供的值“ 5617c8f4b705960e4c314406”不是整数。