简体   繁体   中英

ValueError: invalid literal for int() with base 10 with django.setup()

My initial problem was models not loaded yet and somehow I got info from stackoverflow that django.setup() solves the issue. But then again when I use django.setup() I get this error:

ValueError: invalid literal for int() with base 10

Here is my traceback

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

thanks

This has nothing to do with django.setup() . The error is happening in crawl_web : you are trying to save an item with an integer field, but giving it the value "5617c8f4b705960e4c314406" which is not an integer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM