seawolf
seawolf

Reputation: 2195

python-social-auth failure on Google App Engine

I am attempting to follow Tutorial: Adding Facebook/Twitter/Google Authentication to a Django Application. The only thing I am doing differently is that I am running DjangoAppEngine on the Google App Engine development server, otherwise everything is exactly as per the tutorial.

When I get to Step 4 and actually try to authenticate with Facebook, I am getting a runtime error:

error('illegal IP address string passed to inet_pton',)

Request Method: GET
Request URL:    http://localtest.com:8080/o/complete/facebook/?redirect_state=FG4K...UG1k
Django Version: 1.6.11
Exception Type: RuntimeError
Exception Location: /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py in _MakeRealSyncCall, line 235
Python Executable:  /usr/local/opt/python/bin/python2.7
Python Version: 2.7.11

Obviously FB is passing an approval back to my app, as the request URL includes the callback path.

It appears that something in the GoogleAppEngineLauncher is trying to look up an address and is not receiving the right data in? I'm not really sure.

In trying to resolve this, I've come across a single comment somewhere suggesting to a user that SimpleAuth might be a better way to go, but I don't understand why and I'm not really sure I want to start over if I am just missing something obvious.

Does anyone know why I am getting this error and what I can do to correct it?

Upvotes: 1

Views: 392

Answers (3)

seawolf
seawolf

Reputation: 2195

UPDATE: the original answer (starting with 'HOWEVER') is no longer necessary, just use requests 2.10.0 or above, urllib3 1.15.1 or above, and requests_toolbelt 0.6.2 or above and perform the following in your main():

from requests_toolbelt.adapters import appengine
appengine.monkeypatch()

HOWEVER if you're using older versions of requests and/or urllib3, then you need the patches below:

This can be accomplished using a patched version of requests along with the requests-toolbelt package. Threads that apply:

I've applied all of this and now have python-social-auth and facebook-sdk working in both local test (the dev server) and production (full App Engine).

Upvotes: 1

kzh
kzh

Reputation: 20598

In your vendored libraries, ensure that you have requests_toolbelt. (pip install -t lib requests_toolbelt). Then "monkeypatch" appengine support before python-social-auth ever calls requests. In my project/wsgi.py, I added the following lines:

from requests_toolbelt.adapters import appengine
appengine.monkeypatch()

python-social-auth depends on requests, so it should also exist in your vendor directory.

You must also ensure you are using requests version >= 2.10.0. This has not been released yet, so you can fake it. Edit lib/requests/__init__.py so that __build__ = 0x021000. You also must upgrade the packaged version of urllib3 in the lib/requests/packages/ directory to the latest version.

This is what worked for me.

Upvotes: 0

masnun
masnun

Reputation: 11906

It happens because the Facebook SDK depends on the awesome requests library. However, requests doesn't work on Google App Engine since the platform has some restrictions. You have to use their urlfetch APIs to fetch external contents on Google App Engine.

So yes, the official Facebook SDK won't work. You have to roll your own solution or find one that works. SimpleAuth is one of the solution that is known to have worked.

Upvotes: 1

Related Questions