Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation out of date WRT App Engine requests support #38

Open
kkinder opened this issue May 18, 2015 · 5 comments
Open

Documentation out of date WRT App Engine requests support #38

kkinder opened this issue May 18, 2015 · 5 comments

Comments

@kkinder
Copy link

kkinder commented May 18, 2015

Just reading the latest docs.

Note

Unfortunately, this library will NOT work on Google App Engine due to the requests module not working :(

Fortunately that issue has long since been closed and the requests module does generally work now in GAE. I'm not sure if there are any other issues with using stormpath on GAE.

@rdegges
Copy link
Contributor

rdegges commented May 18, 2015

I tried this about 2 months ago, but it still wasn't working. There's another open issue somewhere talking about it... But I can't seem to find it during a quick skim.

Are you using GAE? If so, wanna help test? I'd be happy to remove the warning if it is indeed working now =)

@kkinder
Copy link
Author

kkinder commented May 20, 2015

So, with much wrangling, I was able to get it to work. Here's what I had to do.

First, your call to platform() in http.py doesn't inside the GAE sandbox. That was simple enough to fix; I just check if it's a GAE environment and imagine that up as another OS:

if 'APPENGINE_RUNTIME' in os.environ.keys():
    USER_AGENT = 'stormpath-sdk-python/%s python/%s Google App Engine' % \
        (STORMPATH_VERSION, '%s.%s.%s' % (vi.major, vi.minor, vi.micro))
else:
    os_info = platform()
    os_versions = {
        'Linux': "%s (%s)" % (linux_distribution()[0], os_info),
        'Windows': "%s (%s)" % (win32_ver()[0], os_info),
        'Darwin': "%s (%s)" % (mac_ver()[0], os_info),
    }

    USER_AGENT = 'stormpath-sdk-python/%s python/%s %s/%s' % (
        STORMPATH_VERSION,
        '%s.%s.%s' % (vi.major, vi.minor, vi.micro),
        system(),
        os_versions.get(system(), ''),
    )

Then, you need to enable open_ssl in your app.yaml file:

libraries:
- name: ssl
  version: latest

Now the ugly part. To bypass an SDK bug, you have to whitelist the _ssl and _socket libraries, then monkey-patch the Python socket library over the SDK one.

That's about it.

Having said that, all of that seems a bit ... unnecessary given that there's a very nice http fetch service built into GAE, which would be preferable to use.

@rdegges
Copy link
Contributor

rdegges commented May 20, 2015

Ouch!

So, this is essentially what I bumped into the last time I tried this.

As the library maintainer, it's sorta a difficult call, but going through all this trouble to maintain compatibility for a service which is breaking HTTP requests on purpose is sorta... odd. It feels wrong to include this stuff in the core library here as it involves a lot of 'hackery' which makes things messy.

Thanks so much for going through all the trouble above though. I think that at the very least, any future user who wants to make this work on GAE can reference this and hopefully take it from there.

@kkinder
Copy link
Author

kkinder commented May 20, 2015

Yeah, Google App Engine is a weird asterisks in the world of Python. I don't know the details, but originally Google said basically "no sockets." Now they said "yes, sockets" but they replace the default sockets library with their own, which plays nicer with their sandbox.

So yeah, it's a little rough... And weird. But GAE is a very nice little SDK if you can live within its limits, and it would be nice if Stormpath could run inside it. Your actual use of the requests module is limited to only a few lines, and for that matter, you could just as easily use urllib which GAE does a better job of supporting.

I'll send over a patch that makes it work, hacky as it is.

@kkinder
Copy link
Author

kkinder commented May 20, 2015

Relevant pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants