ImportError: cannot import name sandbox

一世执手 提交于 2019-12-12 04:46:05

问题


Over the past couple days, this has started cropping up whenever I run dev_appserver.py:

from google.appengine.tools.devappserver2.python import sandbox
ImportError: cannot import name sandbox

Since I was primarily coming across this in the setup of a new environment, I figured it must be a mistake of mine during setup. After enough head-scratching over the past 3 hours, I figured it couldn't be in the new setup, so I loaded up dev_appserver.py in a known-to-be-working environment.

Yet again:

from google.appengine.tools.devappserver2.python import sandbox
ImportError: cannot import name sandbox

None of my app code had been changed, so it had to be something else.


回答1:


It turned out the SDK had changed.

I had a file named appengine_config.py that (specifically for the development server) whitelisted a couple of C modules.

from google.appengine.tools.devappserver2.python import sandbox
sandbox._WHITE_LIST_C_MODULES += ['_ssl', '_socket']

When I disabled these lines, this issue was replaced with another (the one that was the reason those lines were there to mitigate):

File "[...]/devappserver2/python/runtime/sandbox.py", line 1091, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named _socket

Notice the runtime piece in the filepath? Apparently the location of the sandbox module had changed. So I added .runtime to the import path:

from google.appengine.tools.devappserver2.python.runtime import sandbox

Then, after re-enabling those lines, everything was working again! ✅ Mission accomplished.

🎉



来源:https://stackoverflow.com/questions/47112527/importerror-cannot-import-name-sandbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!