Reputation: 1
Good morning, I am trying to use a Google captcha in Otree, I installed recaptcha and create an account that gave me the keys, but when I run the powershell it shows me the following error:
Traceback (most recent call last):
File "c:\users\user\appdata\local\programs\python\python37\lib\site-packages\otree_startup\__init__.py", line 202, in do_django_setup
django.setup()
File "c:\users\user\appdata\local\programs\python\python37\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "c:\users\user\appdata\local\programs\python\python37\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "c:\users\user\appdata\local\programs\python\python37\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "c:\users\user\appdata\local\programs\python\python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "c:\users\user\appdata\local\programs\python\python37\lib\site-packages\captcha\__init__.py", line 18, in <module>
"Setting %s is not of type" % variable, instance_type
django.core.exceptions.ImproperlyConfigured: ('Setting RECAPTCHA_PUBLIC_KEY is not of type', <class 'str'>)
This is the code that I have in my settings, the enviroment.get code is to run the experiment on Heroku.
RECAPTCHA_PUBLIC_KEY = 'RECAPTCHA_PUBLIC_KEY'
RECAPTCHA_PRIVATE_KEY = 'RECAPTCHA_PUBLIC_KEY'
RECAPTCHA_PUBLIC_KEY = environ.get('RECAPTCHA_PUBLIC_KEY')
RECAPTCHA_PRIVATE_KEY = environ.get('RECAPTCHA_PRIVATE_KEY')
The key are numbers and I dont know how to make the captcha works, someone can give a idea??
Upvotes: 0
Views: 990
Reputation: 11
I had this issue. All I had to do was just wrapping str()
:
RECAPTCHA_PUBLIC_KEY = str(environ.get('RECAPTCHA_PUBLIC_KEY'))
RECAPTCHA_PRIVATE_KEY = str(environ.get('RECAPTCHA_PRIVATE_KEY'))
Upvotes: 1
Reputation: 21
I had the same problem with that module and what I had done was:
in settings.py
wrap keys with str()
:
RECAPTCHA_PUBLIC_KEY = str('YOUR_RECAPTCHA_PUBLIC_KEY')
RECAPTCHA_PRIVATE_KEY = str('YOUR_RECAPTCHA_PRIVATE_KEY')
I checked it out by inserting debug prints directly into the site-packages\captcha\__init__.py
like this:
SETTINGS_TYPES = {
"RECAPTCHA_DOMAIN": str,
"RECAPTCHA_PRIVATE_KEY": str,
"RECAPTCHA_PROXY": dict,
"RECAPTCHA_PUBLIC_KEY": str,
"RECAPTCHA_VERIFY_REQUEST_TIMEOUT": int,
}
print(settings.RECAPTCHA_PRIVATE_KEY) # <--added
print(type(settings.RECAPTCHA_PRIVATE_KEY)) # <--added
# Validate settings types.
for variable, instance_type in SETTINGS_TYPES.items():
if hasattr(settings, variable) \
and not isinstance(getattr(settings, variable), instance_type):
raise ImproperlyConfigured(
"Setting %s is not of type" % variable, instance_type
)
and then I typed python manage.py shell
to see the output. And really, type of the RECAPTCHA_PRIVATE_KEY was unicode
instead of str
.
Upvotes: 2