我正在尝试使用Boto3来管理我的GAE应用中的某些EC2实例,但导入Boto3会导致以下错误:
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/Users/squad/Desktop/Squad/Squad/squad.py", line 6, in <module>
from boto3 import Session
File "/Users/squad/Desktop/Squad/Squad/lib/boto3/__init__.py", line 16, in <module>
from boto3.session import Session
File "/Users/squad/Desktop/Squad/Squad/lib/boto3/session.py", line 17, in <module>
import botocore.session
File "/Users/squad/Desktop/Squad/Squad/lib/botocore/session.py", line 32, in <module>
from botocore.loaders import create_loader
File "/Users/squad/Desktop/Squad/Squad/lib/botocore/loaders.py", line 188, in <module>
class Loader(object):
File "/Users/squad/Desktop/Squad/Squad/lib/botocore/loaders.py", line 201, in Loader
CUSTOMER_DATA_PATH = os.path.join(os.path.expanduser('~'),
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 261, in expanduser
import pwd
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 963, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named pwd
我能够很好地使用Boto,所以这绝不是迫切需要,但如果可能的话我宁愿使用Boto3。
我正在使用Python2.7,如果有任何帮助的话。
感谢您的帮助。
答案 0 :(得分:0)
您必须伪造pwd
模块。
使用必要的填充程序创建名为fake_pwd.py
的文件:
class struct_passwd_dummy(object):
def __init__(self, uid):
self.pw_name = "user"
self.pw_passwd = "x"
self.pw_uid = uid
self.pw_gid = uid
self.pw_gecos = "user"
self.pw_dir = "/home/user"
self.pw_shell = "/bin/sh"
def getpwuid(uid):
return struct_passwd_dummy(uid)
然后,在appengine_config.py
中,试试这个黑客:
try:
import boto3
except ImportError:
import sys
import fake_pwd
sys.modules["pwd"] = fake_pwd
import boto3