shubhendu
shubhendu

Reputation: 351

Django python manage.py runserver giving exception Datafile not found, datafile generation failed

After upgrading one of my packages (django-registration), I received this error while trying to run python manage.py runserver

The output was as I have shown below.

I thought that

python3.5/site-packages/confusable_homoglyphs/categories.py

might be missing and I re installed the package confusable_homoglyphs , but to no avail .It threw the same error

Also after that,

a file name =3.0.0.txt was created inside my project folder which had this written below

Requirement already satisfied: confusable_homoglyphs in ./myvenv/lib/python3.5/site-packages

I tried to remove the package and add that package (even inside n outside my virtual env). But it threw the same error as below.

(myvenv) shubhendu@shubhendu-HP-Pavilion-g6-Notebook-PC:/home/foodballbear$ python manage.py runserver
Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f320538d400>
Traceback (most recent call last):
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/confusable_homoglyphs/categories.py", line 141, in <module>
    categories_data = load('categories.json')
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/confusable_homoglyphs/utils.py", line 33, in load
    with open('{}/{}'.format(os.getcwd(), filename), 'r') as file:
FileNotFoundError: [Errno 2] No such file or directory: '/home/foodballbear/categories.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/confusable_homoglyphs/categories.py", line 144, in <module>
    if generate():
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/confusable_homoglyphs/categories.py", line 111, in generate
    file = get(url)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/confusable_homoglyphs/utils.py", line 24, in get
    return urlopen(url).read().decode('utf-8').split('\n')
  File "/usr/lib/python3.5/http/client.py", line 461, in read
    s = self._safe_read(self.length)
  File "/usr/lib/python3.5/http/client.py", line 607, in _safe_read
    chunk = self.fp.read(min(amt, MAXAMOUNT))
  File "/usr/lib/python3.5/socket.py", line 575, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/core/management/base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/core/checks/urls.py", line 16, in check_url_config
    return check_resolver(resolver)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/urls/resolvers.py", line 254, in check
    for pattern in self.url_patterns:
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/urls/resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/foodballbear/myfoodsite/urls.py", line 27, in <module>
    url(r'^accounts/', include('registration.backends.simple.urls')),
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/conf/urls/__init__.py", line 50, in include
    urlconf_module = import_module(urlconf_module)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/registration/backends/simple/urls.py", line 10, in <module>
    from . import views
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/registration/backends/simple/views.py", line 10, in <module>
    from registration.views import RegistrationView as BaseRegistrationView
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/registration/views.py", line 12, in <module>
    from registration.forms import RegistrationForm
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/registration/forms.py", line 19, in <module>
    from . import validators
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/registration/validators.py", line 10, in <module>
    from confusable_homoglyphs import confusables
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/confusable_homoglyphs/confusables.py", line 7, in <module>
    from .categories import unique_aliases, alias
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/confusable_homoglyphs/categories.py", line 147, in <module>
    raise Exception('Datafile not found, datafile generation failed!')
Exception: Datafile not found, datafile generation failed!

Upvotes: 0

Views: 383

Answers (2)

shubhendu
shubhendu

Reputation: 351

This issue has been raised before

https://github.com/vhf/confusable_homoglyphs/issues/7

I can now run my server by manage.py, seems there is an issue with the package

confusable_homoglyphs

It downloads files whenever it gets loaded . It gives problems, when dependencies would frequently get downloaded, which would cause the

ConnectionResetError: [Errno 104] Connection reset by peer

Thanks to link provided in comment, the patch has been applied and will work well with confusable_homoglyphs>=3.0.0.

Running virtualenv with the option --no-site-packages will not include the packages that are installed globally. It may be useful for keeping the package list clean in case it needs to be accessed later

In order to keep environment consistent, I “freeze” the current state of the environment packages

$ pip freeze > requirements.txt

This is my requirements.txt

Django==1.11.1
django-dajax==0.9.2
django-dajaxice==0.7
django-filter==1.1.0
django-redis==4.8.0
djangorestframework==3.6.3
pkg-resources==0.0.0
psycopg2==2.7.3.2
pytz==2017.2
redis==2.10.6

This is my requirements.txt after I added `

confusable_homoglyphs>=3.0.0

` the required version

Django==1.11.1
django-dajax==0.9.2
django-dajaxice==0.7
django-filter==1.1.0
django-redis==4.8.0
djangorestframework==3.6.3
pkg-resources==0.0.0
psycopg2==2.7.3.2
pytz==2017.2
redis==2.10.6
confusable_homoglyphs>=3.0.0

Then I ran pip install -r requirements.txt

(myvenv) shubhendu@shubhendu-HP-Pavilion-g6-Notebook-PC:/home/foodballbear  :  pip install -r requirements.txt 
Obtaining bootstrap from git+git://github.com/earle/django-bootstrap.git@97eb50b3f4932798e7fa8ad4b42f0534d521826d#egg=bootstrap (from -r requirements.txt (line 1))
  Skipping because already up-to-date.
Requirement already satisfied: Django==1.11.1 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 2))
Requirement already satisfied: django-dajax==0.9.2 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 3))
Requirement already satisfied: django-dajaxice==0.7 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 4))
Requirement already satisfied: django-filter==1.1.0 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 5))
Requirement already satisfied: django-redis==4.8.0 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 6))
Requirement already satisfied: djangorestframework==3.6.3 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 7))
Requirement already satisfied: pkg-resources==0.0.0 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 8))
Requirement already satisfied: psycopg2==2.7.3.2 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 9))
Requirement already satisfied: pytz==2017.2 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 10))
Requirement already satisfied: redis==2.10.6 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 11))
Collecting confusable_homoglyphs>=3.0.0 (from -r requirements.txt (line 12))
  Downloading confusable_homoglyphs-3.0.0-py2.py3-none-any.whl (173kB)
    100% |████████████████████████████████| 174kB 828kB/s 
Installing collected packages: bootstrap, confusable-homoglyphs
  Found existing installation: bootstrap 0.1.0
    Uninstalling bootstrap-0.1.0:
      Successfully uninstalled bootstrap-0.1.0
  Running setup.py develop for bootstrap
  Found existing installation: confusable-homoglyphs 2.0.2
    Uninstalling confusable-homoglyphs-2.0.2:
      Successfully uninstalled confusable-homoglyphs-2.0.2
Successfully installed bootstrap confusable-homoglyphs-3.0.0

After that my python manage.py runserver threw no errors

(myvenv) shubhendu@shubhendu-HP-Pavilion-g6-Notebook-PC:/home/foodballbear$ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
December 12, 2017 - 06:08:24
Django version 1.11.1, using settings 'myfoodsite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Upvotes: 1

NIKHIL RANE
NIKHIL RANE

Reputation: 4092

You are trying to access categories.json this file in django you can not access file directly. Due to that exception is occurred.

Use following solution to access the categories.json

from project_name.settings import BASE_DIR
import os

file_path = os.path.join(BASE_DIR, 'categories.json')
categories_data = load(file_path)

BASE_DIR gives you your project directory path after that you want to join your file path by using os.path.join()

Hope this is helps you

Upvotes: 0

Related Questions