V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
cxyfreedom
V2EX  ›  Python

Django 使用 python-social-auth 第三方登录( Google)的问题

  •  
  •   cxyfreedom · 2016-08-29 21:59:40 +08:00 · 3903 次点击
    这是一个创建于 2810 天前的主题,其中的信息可能已经有所发展或是发生改变。

    前期配置

    我已经在项目的 settings.py 中配置了一下内容

    AUTHENTICATION_BACKENDS = (
        'social.backends.google.GoogleOAuth2',
        'django.contrib.auth.backends.ModelBackend',
        'account.authentication.EmailAuthBackend',
    )
    
    SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '<my_key>'
    SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '<my_secret>'
    

    相应的模板中也已经添加了相关链接

    <li class="google"><a href="{% url 'social:begin' backend='google-oauth2' %}">Login with Google</a></li>
    

    urls.py 也添加了对应的内容

    url(r'social-auth/', include('social.apps.django_app.urls', namespace='social')),
    

    Google+ API 也启用了

    问题

    点击Login with Google按钮后,跳转到申请权限后,点击允许按钮之后,报如下错误:

    Exception Value:	
    Authentication failed: HTTPSConnectionPool(host='accounts.google.com', port=443): Max retries exceeded with url: /o/oauth2/token (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x0000000005BE6630>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。',))
    

    想问问有没有 V 友知道怎么解决这个问题吗,还是说我前期的配置中缺少了什么,谢谢

    10 条回复    2016-08-30 16:05:08 +08:00
    kxxoling
        1
    kxxoling  
       2016-08-29 23:25:32 +08:00
    连接失败。。。没爬墙吧?
    cxyfreedom
        2
    cxyfreedom  
    OP
       2016-08-29 23:46:10 +08:00
    @kxxoling 我本地是开了 ss 的, django 跑 server 的话怎么用代理?请指教,谢谢
    shellfly
        3
    shellfly  
       2016-08-30 08:34:58 +08:00   ❤️ 1
    可以把 ss 转换成 http 代理,然后再起 server 之前设置下这个 http_proxy 环境变量
    sylecn
        4
    sylecn  
       2016-08-30 08:39:28 +08:00   ❤️ 1
    直接在墙外测试比较容易。

    ss 客户端没有全局效果,只有 socksv5 代理。倒是可以配置 tsocks ,然后通过 tsocks 运行 manager.py 。但是我一直觉得 tsocks 不是所有情况都能稳定运行。
    kxxoling
        5
    kxxoling  
       2016-08-30 13:13:39 +08:00   ❤️ 1
    SS 没设置全局代理吧?你可以在终端设置一个 http_proxy 或者简单点直接挂个 VPN 。
    cxyfreedom
        6
    cxyfreedom  
    OP
       2016-08-30 13:31:08 +08:00
    @shellfly @kxxoling 我通过 privoxy 把 ss 转成 http 代理, http_proxy 也设置过,但是运行 server ,访问地址报错...

    No server or forwarder data received

    Your request for http://mysite.com:8000/account/login/ could not be fulfilled, because the connection to mysite.com (127.0.0.1) has been closed before Privoxy received any data for this request.
    kxxoling
        7
    kxxoling  
       2016-08-30 15:20:40 +08:00
    @cxyfreedom privoxy 的错误信息?没用过 privoxy 呢。。。总之你先挂 VPN 试试?
    lcc4376
        8
    lcc4376  
       2016-08-30 15:40:01 +08:00   ❤️ 1
    看起來設定沒錯,,,我是用 pip install python-social-auth ,,,, google,fb,twitter 登入都 ok, 還有你有開 vpn 嗎?牆內一定要開的
    cxyfreedom
        9
    cxyfreedom  
    OP
       2016-08-30 15:51:41 +08:00 via iPhone
    @kxxoling VPN 可以通过的...
    cxyfreedom
        10
    cxyfreedom  
    OP
       2016-08-30 16:05:08 +08:00
    @lcc4376 开了 VPN 就可以了。谢谢帮助
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   991 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 54ms · UTC 21:01 · PVG 05:01 · LAX 14:01 · JFK 17:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.