question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with import cities by manage.py, got error

See original GitHub issue

Hello! Today i’ve got an error whe tried to import data using manage.py cities_light. i’ve got that error

[bison@mymachine backend]$ python manage.py cities_light
cities_light WARNING  Assuming local download is up to date for http://download.geonames.org/export/dump/countryInfo.txt
cities_light INFO     Forced import of countryInfo.txt because data do not seem to have installed successfuly yet, note that this is equivalent to --force-import-all.
cities_light INFO     Importing countryInfo.txt
Traceback (most recent call last):
  File "/backend/venv/lib/python3.9/site-packages/django/db/models/fields/__init__.py", line 1823, in get_prep_value
    return int(value)
ValueError: invalid literal for int() with base 10: ''

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/backend/manage.py", line 22, in <module>
    main()
  File "/backend/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/backend/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/backend/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/backend/venv/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/backend/venv/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/backend/venv/lib/python3.9/site-packages/cities_light/management/commands/cities_light.py", line 217, in handle
    self.country_import(items)
  File "/backend/venv/lib/python3.9/site-packages/cities_light/management/commands/cities_light.py", line 312, in country_import
    country = Country.objects.get(geoname_id=items[ICountry.geonameid])
  File "/backend/venv/lib/python3.9/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/backend/venv/lib/python3.9/site-packages/django/db/models/query.py", line 424, in get
    clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs)
  File "/backend/venv/lib/python3.9/site-packages/django/db/models/query.py", line 941, in filter
    return self._filter_or_exclude(False, args, kwargs)
  File "/backend/venv/lib/python3.9/site-packages/django/db/models/query.py", line 961, in _filter_or_exclude
    clone._filter_or_exclude_inplace(negate, args, kwargs)
  File "/backend/venv/lib/python3.9/site-packages/django/db/models/query.py", line 968, in _filter_or_exclude_inplace
    self._query.add_q(Q(*args, **kwargs))
  File "/backend/venv/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1393, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/backend/venv/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1412, in _add_q
    child_clause, needed_inner = self.build_filter(
  File "/backend/venv/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1347, in build_filter
    condition = self.build_lookup(lookups, col, value)
  File "/backend/venv/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1193, in build_lookup
    lookup = lookup_class(lhs, rhs)
  File "/backend/venv/lib/python3.9/site-packages/django/db/models/lookups.py", line 25, in __init__
    self.rhs = self.get_prep_lookup()
  File "/backend/venv/lib/python3.9/site-packages/django/db/models/lookups.py", line 77, in get_prep_lookup
    return self.lhs.output_field.get_prep_value(self.rhs)
  File "/backend/venv/lib/python3.9/site-packages/django/db/models/fields/__init__.py", line 1825, in get_prep_value
    raise e.__class__(
ValueError: Field 'geoname_id' expected a number but got ''.

So, in the backend/venv/lib/python3.9/site-packages/cities_light/management/commands/cities_light.py after 308 line i put the code

            if not items[ICountry.geonameid]:
                print(ICountry.geonameid)
                print(items)

it returns

16

['CS', 'SCG', '891', 'YI', 'Serbia and Montenegro', 'Belgrade', '102350', '10829175', 'EU', '.cs', 'RSD', 'Dinar', '381', '#####', '^(\\d{5})$', 'cu,hu,sq,sr', '', 'AL,HU,MK,RO,HR,BA,BG']

Could you help with that? Do you have any ideas?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:16

github_iconTop GitHub Comments

2reactions
marianoeramirezcommented, Sep 11, 2021

Hi everyone, here is a draft PR to solve this issue. https://github.com/yourlabs/django-cities-light/pull/255

Please test installing from the branch: pip install git+https://github.com/yourlabs/django-cities-light.git@fix/import-error

2reactions
marianoeramirezcommented, Sep 11, 2021

She is filtering the cities to be imported only to the places from France.

I will try to provide a solution for this within the project today. And let you know

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django Cities import error - python - Stack Overflow
I can't get to import data with manage.py cities --import=all , I don't have idea of why this is happening. Here is the...
Read more >
django-cities returns a MultipleObjectsReturned exception ...
I am facing similar issue. While importing postal codes, I am getting following error. Please find the stack trace. ... cities.models.
Read more >
Time zones - Django documentation
When support for time zones is enabled, Django stores datetime information in UTC in the database, uses time-zone-aware datetime objects internally, ...
Read more >
Make a Location-Based Web App With Django and GeoDjango
In this step-by-step Python tutorial, you'll learn how to use Django and GeoDjango to build a location-based web application from scratch.
Read more >
How To Build a Weather App in Django - DigitalOcean
python manage.py runserver. In your web browser, visit the admin dashboard by going to 127.0.0.1:8000/admin . The reason why ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found