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

2016-08-29 21:59:40 +08:00
 cxyfreedom

前期配置

我已经在项目的 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 友知道怎么解决这个问题吗,还是说我前期的配置中缺少了什么,谢谢

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

ss 客户端没有全局效果,只有 socksv5 代理。倒是可以配置 tsocks ,然后通过 tsocks 运行 manager.py 。但是我一直觉得 tsocks 不是所有情况都能稳定运行。
kxxoling
2016-08-30 13:13:39 +08:00
SS 没设置全局代理吧?你可以在终端设置一个 http_proxy 或者简单点直接挂个 VPN 。
cxyfreedom
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
2016-08-30 15:20:40 +08:00
@cxyfreedom privoxy 的错误信息?没用过 privoxy 呢。。。总之你先挂 VPN 试试?
lcc4376
2016-08-30 15:40:01 +08:00
看起來設定沒錯,,,我是用 pip install python-social-auth ,,,, google,fb,twitter 登入都 ok, 還有你有開 vpn 嗎?牆內一定要開的
cxyfreedom
2016-08-30 15:51:41 +08:00
@kxxoling VPN 可以通过的...
cxyfreedom
2016-08-30 16:05:08 +08:00
@lcc4376 开了 VPN 就可以了。谢谢帮助

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/302552

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX