80π
in django 4.0 we dont have force_text
https://docs.djangoproject.com/en/4.0/ref/utils/#module-django.utils.encoding
instead change force_text
to force_str
linux:
YOUR_VENV/lib/PYTHON_VERSION/site-packages/graphene_django/utils/utils.py
windows:
YOUR_VENV/lib/site-packages/graphene_django/utils/utils.py
from django.utils.encoding import force_text
to
from django.utils.encoding import force_str
and
def _camelize_django_str(s):
if isinstance(s, Promise):
s = force_text(s)
return to_camel_case(s) if isinstance(s, six.string_types) else s
to
def _camelize_django_str(s):
if isinstance(s, Promise):
s = force_str(s)
return to_camel_case(s) if isinstance(s, six.string_types) else s
32π
Based on answer given by @Osman.
The problem seems to be occuring with Django-4. Till the PR gets merged, probably this monkeypatching might work (not tested in prod):
import django
from django.utils.encoding import force_str
django.utils.encoding.force_text = force_str
Put this in entryfile. I kept it in settings.py for time being.
- [Django]-Override default queryset in Django admin
- [Django]-Pytest.mark.parametrize with django.test.SimpleTestCase
- [Django]-How to add custom field in ModelSerializer?
14π
In Django version 4> just paste this snippet to your settinsg.py. Preferably on the top
import django
from django.utils.encoding import force_str
django.utils.encoding.force_text = force_str
- [Django]-ImportError: Failed to import test module:
- [Django]-How to make Django's DateTimeField optional?
- [Django]-How to access array elements in a Django template?
12π
force_text
is removed from Django 4.0 but the old version of graphene_django still uses force_text
in utils.py
. *You can see Features removed in 4.0.
So, upgrading graphene-django
will solve the error easily:
pip install graphene-django --upgrade
Or, replace force_text
with force_str
as shown below:
# "utils.py"
# from django.utils.encoding import force_text # Line 6
from django.utils.encoding import force_str # Line 6
# s = force_text(s) # Line 29
s = force_str(s) # Line 29
These are the paths to utils.py
for Linux and Windows:
Linux:
<your_venv>/lib/<python_version>/site-packages/graphene_django/utils/utils.py
Windows:
<your_venv>/lib/site-packages/graphene_django/utils/utils.py
- [Django]-Django error β matching query does not exist
- [Django]-How to manually assign imagefield in Django
- [Django]-Django select only rows with duplicate field values
- [Django]-Storing an Integer Array in a Django Database
- [Django]-Django models: get list of id
- [Django]-Django Order By Date, but have "None" at end?
0π
You can install graphene-django version 3.0.0b7
run the following command in your terminal:
pip install graphene-django==3.0.0b7
Itβs beta version, but i donβt know why graphene-django 2.15 doesβnt work, when patch note said they fixed issue since 2.8.1 version.
Thankβs to @Behoston from this Github issue for this solution
- [Django]-Where is a good place to work on accounts/profile in Django with the Django registration app?
- [Django]-How to create an object for a Django model with a many to many field?
- [Django]-Django Background Task
0π
I have been running into a similar issue whereby including "graphql_jwt.refresh_token.apps.RefreshTokenConfig"
in INSTALLED_APPS
leads to the following import error:
ImportError: cannot import name 'force_text' from 'django.utils.encoding'
I added this at the top of settings.py:
import django
from django.utils.encoding import force_str
django.utils.encoding.force_text = force_str
And was greeted with this error:
ImportError: cannot import name 'ugettext' from 'django.utils.translation'
Where I then added the following to the top of settings.py:
from django.utils.translation import gettext, gettext_lazy
django.utils.translation.ugettext = gettext
django.utils.translation.ugettext_lazy = gettext_lazy
And delightfully resolved this error:
TypeError: __init__() got an unexpected keyword argument 'providing_args'
Django version 4.2.
- [Django]-Django: detect admin login in view or template
- [Django]-Django β Static file not found
- [Django]-Coercing to Unicode: need string or buffer, NoneType found when rendering in django admin
0π
For people that want a release independent version:
try:
from django.utils.encoding import force_text
except:
from django.utils.encoding import force_str as force_text
- [Django]-How to override and extend basic Django admin templates?
- [Django]-Django's Double Underscore
- [Django]-Storing an Integer Array in a Django Database