GAE Python - Error during the import _winreg

87 views
Skip to first unread message

Andre Avilla

unread,
May 14, 2017, 10:45:56 AM5/14/17
to Google App Engine

Hi,


I use GAE - Google Application Engine Python - and my project raises error during 'import requests' when it is ran under GAE sandbox (locally).


'platform' now is used in requests/utils.py after the commit 'proxy bypass on Windows without DNS lookups' ( https://github.com/kennethreitz/requests/commits/master/requests/utils.py )


GAE doesn't have _winreg in sys.modules and the _winreg is called by platform.py. In platform.py: system() function -> uname() -> win32_ver() -> import _winreg.



I don't know why GAE doesn't import _winreg. It seems GAE was developed in Unix-like platform.


GAE uses requests library too, but it uses an old version.


If I copy an old requests version to my project (without import platform) and it works nice. I'd like to use update version. Besides I believe that can became a problem to other developers, because all documents say to developers install requests (third-part libraries) inside their GAE project (pip install requests -t lib)


I'm not sure if this is a problem with the Requests project or Google.


Regards,
André

Andre Avilla

unread,
May 14, 2017, 11:16:46 AM5/14/17
to Google App Engine
My landscape:

Windows 10
Python 2.7
GAE 1.9.53

I opened an issue to Requests Project:

I also opened an issue to Google:



George (Cloud Platform Support)

unread,
May 15, 2017, 3:47:30 PM5/15/17
to Google App Engine
Hello Andre, 

This problem is now enjoying developer attention under issue 38290292. You may follow all developments in real time there, up to the final solution. 

Andre Avilla

unread,
May 15, 2017, 8:47:49 PM5/15/17
to Google App Engine
George,

I implemented the workaround below as suggested in issue and it was great, everything worked fine under sandbox. 

As a workaround before we release a fix, please try adding following:
- goto <sdk_root>\google\appengine\tools\devappserver2\python\sandbox.py
- find the definition of   _WHITE_LIST_C_MODULES = [xxx]
   add following two lines to the list:  
    '_winreg',
    '_ctypes',
- try your app again.

Thanks!

George (Cloud Platform Support)

unread,
May 18, 2017, 9:54:34 AM5/18/17
to Google App Engine
The provided extra info seems quite helpful. It will be taken into consideration by Developers. 

Attila-Mihaly Balazs

unread,
May 29, 2017, 7:48:35 AM5/29/17
to Google App Engine
There was a similar problem with Flask / click some times back: https://github.com/pallets/click/issues/594

The root of the issue is that some modules (like requests, click, etc) have an "if Windows do this else do that" logic. Now AppEngine is most definitely Linux in production, however the development server does not emulate this properly and the "if Windows" kind of logic gets tripped up (ie. "this is Windows but I can't import the Windows specific modules because the devserver prevents me from doing so since they are not available in production").

IMHO the devserver should be fixed such that it reports "Linux" as the current platform.
Reply all
Reply to author
Forward
0 new messages