python: error when calling platform.platform()

74 views
Skip to first unread message

Michael Spainhower

unread,
Aug 10, 2015, 8:51:13 PM8/10/15
to Google App Engine
I have a 3rd party library (Authy) that calls `platform.platform()` (https://docs.python.org/2/library/platform.html#platform.platform).  Unfortunately, when this function tries to get the libc version (assuming so, function is named libc_ver), it tries to open the file /usr/bin/python.  Obviously this does not work.

Is there an established approach to handle this?  It seems like the kind of thing that would be stubbed out by GAE SDK (returning its own platform string, or an empty string).  I'll probably submit a PR for better exception handling with the library maintainer, but in the meantime I'd love a reasonable mitigation (I can think of some nasty hacks that would work).

Cheers,
--Spain

Patrice (Cloud Platform Support)

unread,
Aug 11, 2015, 9:55:48 AM8/11/15
to Google App Engine
Hi!

What do you want exactly? The platform.platform call to work? I don't think it can, unless you can change where it tries to get libc's version.

Do you want to be able to look in the fs of your instance? You can't. 

If what you want is a "platform string", you could always create your own string, put it in an environment variable (in your app.yaml) and get it there?

If you could explain what you expect to get and do with the platform.platform return, I'd be happy to look into ways for you to do it.

Cheers!

Michael Spainhower

unread,
Aug 11, 2015, 10:39:37 AM8/11/15
to Google App Engine
I want the 3rd party library (Authy) to work without modification in a way that is unlikely to break upon a change in that library, GAE, or the python 2.7 native API.  Authy only uses the result of platform.platform() to create its user agent string for http requests, so it doesn't really matter what it returns. The hack I am currently using, that technically works, is

import platform

platform
.platform = lambda aliased=0, terse=0: 'GAE'


This may be as good as it gets until the 3rd party library includes better exception handling, but I am happy to solicit solutions that may be less likely to break.

Patrice (Cloud Platform Support)

unread,
Aug 12, 2015, 12:45:57 PM8/12/15
to Google App Engine
Hmmm, I see.

Well for now your workaround is definitely something. As Authy is a 3rd party, I must admit I'm not used to it. I'll try to see if I can think of something else as well. In the meantime, maybe someone else on the google group will have a solution for you :).

Cheers!
Reply all
Reply to author
Forward
0 new messages