Forums

pythonanywhere web2py social-auth returning error

I am new to web2py and python. I hosted my web2py app on pythonanywhere where I'm using social login. After logging in (say via facebook), I get the following error when it is trying to redirect to another page on my same app (not any external website) :

<class 'urllib2.URLError'> <urlopen error Tunnel connection failed: 403 Forbidden> error

This is the part which takes care of login. (I'm trying to redirect to the 'hello' page after successful log in) :

def index():
    user_auth = auth.login(next=URL('default/hello'))
    welcomeMessage = T('Welcome ! Please  log in')
    return dict(welcomeMessage=welcomeMessage, user_auth = user_auth)

Could you please help?

[edited by admin: formatting]

Could you post more detailed exception information? For example, what do you see in your web app's error log (which you can access from the "Web" tab)?

Thanks for your response. Here is more information about the exception :

<class 'urllib2.URLError'> <urlopen error Tunnel connection failed: 403 Forbidden>

Version

web2py™ Version 2.8.2-stable+timestamp.2013.11.28.13.54.07

Python Python 2.7.5+: /usr/local/bin/uwsgi (prefix: /usr)

Traceback (most recent call last):

File "/home/debtsetgo/web2py/gluon/restricted.py", line 217, in restricted

exec ccode in environment

File "/home/debtsetgo/web2py/applications/DeboApp/controllers/default.py", line 153, in <module>

File "/home/debtsetgo/web2py/gluon/globals.py", line 372, in <lambda>

self._caller = lambda f: f()

File "/home/debtsetgo/web2py/applications/DeboApp/controllers/default.py", line 16, in index

user_auth = auth.login()

File "/home/debtsetgo/web2py/gluon/tools.py", line 2357, in login

cas_user = cas.get_user()

File "/home/debtsetgo/web2py/gluon/contrib/login_methods/rpx_account.py", line 85, in get_user

auth_info_json = fetch(self.auth_url + '?' + data)

File "/home/debtsetgo/web2py/gluon/tools.py", line 4213, in fetch

html = urllib2.urlopen(req).read()

File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen

return _opener.open(url, data, timeout)

File "/usr/lib/python2.7/urllib2.py", line 404, in open

response = self._open(req, data)

File "/usr/lib/python2.7/urllib2.py", line 422, in _open

'_open', req)

File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain

result = func(*args)

File "/usr/lib/python2.7/urllib2.py", line 1222, in https_open

return self.do_open(httplib.HTTPSConnection, req)

File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open

raise URLError(err)

URLError: <urlopen error Tunnel connection failed: 403 Forbidden>

Error snapshot help <class 'urllib2.URLError'>(<urlopen error Tunnel connection failed: 403 Forbidden>)

inspect attributes

Frames

File /home/debtsetgo/web2py/gluon/restricted.py in restricted at line 217 code arguments variables

File /home/debtsetgo/web2py/applications/DeboApp/controllers/default.py in <module> at line 153 code arguments variables

File /home/debtsetgo/web2py/gluon/globals.py in <lambda> at line 372 code arguments variables

File /home/debtsetgo/web2py/applications/DeboApp/controllers/default.py in index at line 16 code arguments variables

File /home/debtsetgo/web2py/gluon/tools.py in login at line 2357 code arguments variables

File /home/debtsetgo/web2py/gluon/contrib/login_methods/rpx_account.py in get_user at line 85 code arguments variables

File /home/debtsetgo/web2py/gluon/tools.py in fetch at line 4213 code arguments variables

File /usr/lib/python2.7/urllib2.py in urlopen at line 127 code arguments variables

File /usr/lib/python2.7/urllib2.py in open at line 404 code arguments variables

File /usr/lib/python2.7/urllib2.py in _open at line 422 code arguments variables

File /usr/lib/python2.7/urllib2.py in _call_chain at line 382 code arguments variables

File /usr/lib/python2.7/urllib2.py in https_open at line 1222 code arguments variables

File /usr/lib/python2.7/urllib2.py in do_open at line 1184 code arguments variables

Function argument list

(self=<urllib2.HTTPSHandler instance>, http_class=<class httplib.HTTPSConnection>, req=<urllib2.Request instance>)

Code listing try:

        h.request(req.get_method(), req.get_selector(), req.data, headers)

    except socket.error, err: # XXX what error?

        h.close()

        raise URLError(err)

    else:
        try:
            r = h.getresponse(buffering=True)
        except TypeError: # buffering kw not supported

Variables err error('Tunnel connection failed: 403 Forbidden',) global URLError <class 'urllib2.URLError'>

Ah, I think I see the problem -- you need to reload your web application. When you upgraded to a Hacker account, your web app didn't pick up the new settings, so it's still restricted to accessing external sites from our whitelist. If you reload it, it will pick up the new settings for your paid account and it should start working right away.

Thanks a lot! Reloading the app resolved the issue :)

Great! Thanks for confirming that.