Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django NameError: name 'os' is not defined [closed]

Tags:

python

django

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'
like image 840
Nima Avatar asked Aug 04 '12 11:08

Nima


People also ask

How do I fix NameError name OS is not defined?

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 .


1 Answers

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'
like image 190
yedpodtrzitko Avatar answered Sep 19 '22 07:09

yedpodtrzitko