3

While importing CredentialsField from oauth2client.django_orm, I am getting:

Import Error: No module named django_orm

I've already installed the prerequisites: django-orm and python-oauth2.

DavidG
  • 24,279
  • 14
  • 89
  • 82
dhiraj kumar
  • 109
  • 2
  • 6

3 Answers3

5

It looks like there's been a change on the OAuth2 library:

Refactor all django-related code into oauth2client.contrib.django_util. Add DjangoORMStorage, remove FlowField. (#546)

You can check this here.

Perhaps you can try something like this (I don't get any import errors when running it, but I am not sure it works):

from oauth2client.contrib.django_util.storage import DjangoORMStorage
from oauth2client.contrib.django_util.models import CredentialsField
Rodrigo
  • 101
  • 2
  • 5
  • Just an update, I have tried it now and it seems to be working fine. I can save the credentials on the CredentialsField and retrieve it using DjangoORMStorage. – Rodrigo Oct 21 '16 at 14:27
2

Documentation on Drive API Guide isn't upto date (Last updated in May 2015).

Use these imports instead:

from oauth2client.contrib.django_orm import CredentialsField
from oauth2client.contrib.django_orm import FlowField
from oauth2client.contrib.django_orm import Storage

If you're following API Guide, then more imports will break. Developers of oauth2client have moved all non-core modules (django_orm, xsrfutil, appengine, etc.) to contrib. Refer to oauth2client source code if you get more ImportErrors.

narendra-choudhary
  • 4,582
  • 4
  • 38
  • 58
0

It looks like the oauth2client library has since been deprecated. Check out the more up to date google-auth library https://google-auth.readthedocs.io

To create a credentials object with an auth token: https://google-auth.readthedocs.io/en/latest/user-guide.html#user-credentials

import google.oauth2.credentials

credentials = google.oauth2.credentials.Credentials(
    'access_token')
mpkasp
  • 343
  • 3
  • 10