lamby / django-slack

Slack integration for Django, using the templating engine to generate messages
https://django-slack.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
241 stars 57 forks source link

AttributeError: 'dict' object has no attribute 'file_charset' #84

Closed Northshoot closed 6 years ago

Northshoot commented 6 years ago

I followed simple example on from the docs, however, getting the error

  File "...../handlers.py", line 61, in request_arrived
    }, channel='userrequest', username='vdpo')
  File "...../e/lib/python3.6/site-packages/django_slack/api.py", line 76, in slack_message
    django_slack='django_slack/{}'.format(k),
  File ".....//lib/python3.6/site-packages/django/template/loader.py", line 61, in render_to_string
    template = get_template(template_name, using=using)
  File ".....//lib/python3.6/site-packages/django/template/loader.py", line 15, in get_template
    return engine.get_template(template_name)
  File "...../e/lib/python3.6/site-packages/django/template/loaders/base.py", line 24, in get_template
    contents = self.get_contents(origin)
  File ".....//lib/python3.6/site-packages/django/template/loaders/filesystem.py", line 23, in get_contents
    with open(origin.name, encoding=self.engine.file_charset) as fp:
AttributeError: 'dict' object has no attribute 'file_charset'

template:

{% extends django_slack %}

{% block text %}
Message text here: {{ foo }}
{% endblock %}

call

 slack_message('message.slack', {
            'foo': 'hello',
}, channel='bottest', username='mybot')
lamby commented 6 years ago

@Northshoot Huh, weird. Can you add some quck debugging? https://gist.github.com/lamby/f94302bd90e5aa0ab1d9815662c8c441/raw

Northshoot commented 6 years ago

sure thing

            print("TEMPLATE", repr(template))
            print("v", repr( v ))
            print("k", repr(k))

output

TEMPLATE 'message.slack'
v {'default': '', 'required': 0}
k 'text'

I am using Django 2 and python 3.6

Northshoot commented 6 years ago

I changed path in setting and removed

django.template.loaders.app_directories.Loader

So the error is gone and no error is given, however messages do not get posted.

I went for the native

python-slackclient

lamby commented 6 years ago

You will need django.template.loaders.app_directories.Loader for it to find django-slack's own internal templates -- that is a red herring and you will need to replace that :)

So, I can't reproduce this. Actually, looking at the traceback:

    with open(origin.name, encoding=self.engine.file_charset) as fp:
AttributeError: 'dict' object has no attribute 'file_charset'

Why is self.engine a dictionary? We don't set that in django-slack and I can't quite see how it could have broken it. Can you paste your entire TEMPLATES from your settings? Something is fishy there!

lamby commented 6 years ago

@Northshoot Any luck?

Northshoot commented 6 years ago

hey, I dropped this library and when with the native api.

lamby commented 6 years ago

@Northshoot Aw. Perhaps could you try again quickly? This is really the only way open source software can get fixed… especially as I can't seem to reproduce this :(

lamby commented 6 years ago

@Northshoot Any luck? :)

lamby commented 6 years ago

@Northshoot Just wondering if you'd had the chance to look at this yet? Would be great to get this fixed.

lamby commented 6 years ago

Okay, there's nothing really to do here alas.. :(

151henry151 commented 2 years ago

i am having this same error.

`/home/henry/EvergreenApp/venv/lib/python3.7/site-packages/braces/views/_forms.py changed, reloading. Watching for file changes with StatReloader Performing system checks...

System check identified some issues:

WARNINGS: foodtaskerapp.Customer: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'. HINT: Configure the DEFAULT_AUTO_FIELD setting or the FoodtaskerappConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'. foodtaskerapp.Driver: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'. HINT: Configure the DEFAULT_AUTO_FIELD setting or the FoodtaskerappConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'. foodtaskerapp.Meal: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'. HINT: Configure the DEFAULT_AUTO_FIELD setting or the FoodtaskerappConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'. foodtaskerapp.Order: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'. HINT: Configure the DEFAULT_AUTO_FIELD setting or the FoodtaskerappConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'. foodtaskerapp.OrderDetails: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'. HINT: Configure the DEFAULT_AUTO_FIELD setting or the FoodtaskerappConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'. foodtaskerapp.Restaurant: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'. HINT: Configure the DEFAULT_AUTO_FIELD setting or the FoodtaskerappConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.

System check identified 6 issues (0 silenced).

You have 8 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, oauth2_provider. Run 'python manage.py migrate' to apply them. January 01, 2022 - 04:21:19 Django version 3.2.10, using settings 'foodtasker.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. Exception in thread django-main-thread: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, self._kwargs) File "/home/henry/EvergreenApp/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 64, in wrapper fn(*args, *kwargs) File "/home/henry/EvergreenApp/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 138, in inner_run handler = self.get_handler(args, options) File "/home/henry/EvergreenApp/venv/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler handler = super().get_handler(*args, **options) File "/home/henry/EvergreenApp/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 65, in get_handler return get_internal_wsgi_application() File "/home/henry/EvergreenApp/venv/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 45, in get_internal_wsgi_application return import_string(app_path) File "/home/henry/EvergreenApp/venv/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string module = import_module(module_path) File "/usr/lib/python3.7/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1006, in _gcd_import File "", line 983, in _find_and_load File "", line 967, in _find_and_load_unlocked File "", line 677, in _load_unlocked File "", line 728, in exec_module File "", line 219, in _call_with_frames_removed File "/home/henry/EvergreenApp/foodtasker/wsgi.py", line 20, in application = DjangoWhiteNoise(application) File "/home/henry/EvergreenApp/venv/lib/python3.7/site-packages/whitenoise/django.py", line 38, in init self.configure_from_settings(settings) File "/home/henry/EvergreenApp/venv/lib/python3.7/site-packages/whitenoise/django.py", line 48, in configure_from_settings self.charset = settings.FILE_CHARSET File "/home/henry/EvergreenApp/venv/lib/python3.7/site-packages/django/conf/init.py", line 83, in getattr val = getattr(self._wrapped, name) AttributeError: 'Settings' object has no attribute 'FILE_CHARSET'

`

lamby commented 2 years ago

This looks like a different bug - it is about django.conf.settings.FILE_CHARSET. Are you using a very new version of Django?

151henry151 commented 2 years ago

hi lamby -- yes i am using a very new version of django

lamby commented 2 years ago

Oh, it is whitenoise that is using the (deprecated) settings.FILE_CHARSET setting here, so this is surely a bug there:

File "/home/henry/EvergreenApp/venv/lib/python3.7/site-packages/whitenoise/django.py", line 48, in configure_from_settings
self.charset = settings.FILE_CHARSET
let-clarence-code commented 2 years ago

@lamby is there a timeline for a fix for this?

lamby commented 2 years ago

No timeline from me. As I currently understand it, this is a bug in whitenoise, not in django-slack...? I would speak to the whitenoise developers.