使用Boto3从googleappengin管理AWS

2024-05-17 18:55:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用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,如果这有帮助的话。在

谢谢你的帮助。在


Tags: inpyimportlibgooglelinecontentsusers
1条回答
网友
1楼 · 发布于 2024-05-17 18:55:17

您必须伪造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中,尝试以下方法:

^{pr2}$

相关问题 更多 >