2014-09-26 114 views
13

我在我的網站中使用python-social-auth API進行身份驗證。 但我得到一個異常`不能導入名稱is_secure_transport。無法導入名稱is_secure_transport

下面是跟蹤。

Django 1.7 
Python Version: 2.7.6 
Installed Applications: 
('django.contrib.admin', 
'django.contrib.auth', 
'django.contrib.contenttypes', 
'django.contrib.sessions', 
'django.contrib.messages', 
'django.contrib.staticfiles', 
'django.contrib.sites', 
'social.apps.django_app.default', 
'login') 
Installed Middleware: 
('django.contrib.sessions.middleware.SessionMiddleware', 
'django.middleware.common.CommonMiddleware', 
'django.middleware.csrf.CsrfViewMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware', 
'django.middleware.clickjacking.XFrameOptionsMiddleware') 


Traceback: 
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response 
    111.      response = wrapped_callback(request, *callback_args, **callback_kwargs) 
File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/utils.py" in wrapper 
    49.            backend, uri) 
File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/utils.py" in load_backend 
    29.  Backend = get_backend(BACKENDS, name) 
File "/usr/local/lib/python2.7/dist-packages/social/backends/utils.py" in get_backend 
    51.   load_backends(backends, force_load=True) 
File "/usr/local/lib/python2.7/dist-packages/social/backends/utils.py" in load_backends 
    33.    backend = module_member(auth_backend) 
File "/usr/local/lib/python2.7/dist-packages/social/utils.py" in module_member 
    23.  module = import_module(mod) 
File "/usr/local/lib/python2.7/dist-packages/social/utils.py" in import_module 
    17.  __import__(name) 
File "/usr/local/lib/python2.7/dist-packages/social/backends/facebook.py" in <module> 
    12. from social.backends.oauth import BaseOAuth2 
File "/usr/local/lib/python2.7/dist-packages/social/backends/oauth.py" in <module> 
    4. from requests_oauthlib import OAuth1 
File "/usr/local/lib/python2.7/dist-packages/requests_oauthlib/__init__.py" in <module> 
    3. from .oauth2_auth import OAuth2 
File "/usr/local/lib/python2.7/dist-packages/requests_oauthlib/oauth2_auth.py" in <module> 
    3. from oauthlib.oauth2 import is_secure_transport 

Exception Type: ImportError at /login/google-oauth2/ 
Exception Value: cannot import name is_secure_transport 
+2

我的猜測是,你可能有一箇舊版本的'oauthlib'嘗試將它升級到0.6.x – karthikr 2014-09-26 04:30:22

+0

thanx @karthikr升級爲我工作...現在得到'HTTPError at/complete/google-oauth2/ 401客戶端錯誤:未經授權的任何想法...... – HadeS 2014-09-28 15:13:13

+0

確保您提供了文檔 – karthikr 2014-09-28 17:35:41

回答

10

更新oauthlib版本絕對有效。

只是這樣做:

sudo pip install --upgrade oauthlib 
+0

此解決方案並不總是有效。 – Veltro 2016-08-02 09:22:02

6

應該卸載tweepy,升級oauthlib然後重新安裝tweepy爲根:

sudo pip uninstall tweepy 
sudo pip install oauthlib --upgrade 
sudo apt-get install python-tweepy 

有同樣的問題,這個工作對我罰款。

+2

這把我整理出來。我最近不得不升級tweepy,因爲:http://stackoverflow.com/a/18580472/3563897。事實證明,我需要徹底改革才能實現。謝謝! – FredFury 2015-12-14 08:41:47

+1

已經嘗試了其他一些事情(包括接受的答案),這是爲我修復它 – 5uperdan 2016-06-03 15:37:38