When I try to follow this tutorial to install Google-auth2 on my Django 1.4 I get this error:
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
import settings
File "/home/ubuntu/xx/settings.py", line 140, in <module>
GOOGLE_OAUTH2_CLIENT_ID = os.environ['GOOGLE_OAUTH2_CLIENT_ID']
NameError: name 'os' is not defined
This line is:
139- LOGIN_REDIRECT_URL = '/'
**140- GOOGLE_OAUTH2_CLIENT_ID = os.environ['GOOGLE_OAUTH2_CLIENT_ID']**
141- GOOGLE_OAUTH2_CLIENT_SECRET = os.environ['GOOGLE_OAUTH2_CLIENT_SECRET']
142- GOOGLE_WHITE_LISTED_DOMAINS = ['mydomain.org']
SOCIAL_AUTH_USER_MODEL = 'auth.User'
The Python "NameError: name 'os' is not defined" occurs when we use the os module without importing it first. To solve the error, import the os module before using it - import os .
You try to use something from module os
, which is not imported, thus you cannot use it.
In order to fix this problem, add an import of that module somewhere at the beginning of settings.py
:
import os
Additionally, if you don't have GOOGLE_OAUTH2_CLIENT_ID
in os.environ
, don't load it from there. Instead, set it directly in settings.py
:
GOOGLE_OAUTH2_CLIENT_ID = 'your-actual-client-id-value'
Or, you can set it first, in your shell, before running the script:
export GOOGLE_OATH2_CLIENT_ID='your-actual-client-id-value'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With