- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我 pip install --upgrade google-cloud-storage -t libs
到我的应用引擎应用。
在 appengine_config.py 中,我添加了:
vendor.add('libs')
vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'libs'))
它适用于在线 App Engine,但不适用于本地 App Engine 沙箱。
ERROR 2016-10-03 00:22:01,311 wsgi.py:263]
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/charlesng/Documents/Codes/python/web/myapp/src/main.py", line 19, in <module>
from handlers import page_handlers, user_handlers, repo_handlers, doc_handlers
File "/Users/charlesng/Documents/Codes/python/web/myapp/src/handlers/repo_handlers.py", line 28, in <module>
from google.cloud import storage
File "/Users/charlesng/Documents/Codes/python/web/myapp/src/libs/google/cloud/storage/__init__.py", line 42, in <module>
from google.cloud.storage.batch import Batch
File "/Users/charlesng/Documents/Codes/python/web/myapp/src/libs/google/cloud/storage/batch.py", line 29, in <module>
from google.cloud.exceptions import make_exception
File "/Users/charlesng/Documents/Codes/python/web/myapp/src/libs/google/cloud/exceptions.py", line 24, in <module>
from google.cloud._helpers import _to_bytes
File "/Users/charlesng/Documents/Codes/python/web/myapp/src/libs/google/cloud/_helpers.py", line 62, in <module>
_USER_ROOT = os.path.expanduser('~')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 262, in expanduser
userhome = pwd.getpwuid(os.getuid()).pw_dir
KeyError: 'getpwuid(): uid not found: 429123195'
文件夹结构:
myapp/
/src/main.py
/src/libs
/env/(virtualenv files)
/env/lib
通常,如果您 pip 一个库,这些文件位于 lib/中,但对于 App Engine 第三方库,我们必须 pip -t libs ,以便它们位于 libs 而不是 lib 中。
当我使用 python2 或 python3 时,从 google.cloud 导入存储,它们很好,但不运行 appengine 沙箱,因为它调用 src/libs/google/cloud 而不是 env/lib/google/cloud。
我应该如何解决这个问题?任何建议或指导将不胜感激。
最佳答案
不确定这是否完全回答了您的问题,但是,我假设您正在使用 Google App Engine SDK在您的计算机上本地启动该应用程序。这使用了经过修补的 os 模块进行沙箱:
/tmp/google_appengine$ cat google/appengine/tools/devappserver2/python/sandbox.py
...
...
...
def apply_policy(self, module_dict):
"""Apply this policy to the provided module dict.
In order, one of the following will apply:
- Symbols in overrides are set to the override value.
- Symbols in deletes are removed.
- Whitelisted symbols and symbols with a constant type are unchanged.
- If a default stub is set, all other symbols are replaced by it.
- If default_pass_through is True, all other symbols are unchanged.
- If default_pass_through is False, all other symbols are removed.
Args:
module_dict: The module dict to be filtered.
"""
for symbol in module_dict.keys():
if symbol in self.overrides:
module_dict[symbol] = self.overrides[symbol]
elif symbol in self.deletes:
del module_dict[symbol]
elif not (symbol in self.whitelist or
isinstance(module_dict[symbol], self.constant_types) or
(symbol.startswith('__') and symbol.endswith('__'))):
if self.default_stub:
module_dict[symbol] = self.default_stub
elif not self.default_pass_through:
del module_dict[symbol]
_MODULE_OVERRIDE_POLICIES = {
'os': ModuleOverridePolicy(
default_stub=stubs.os_error_not_implemented,
whitelist=['altsep', 'curdir', 'defpath', 'devnull', 'environ', 'error',
'fstat', 'getcwd', 'getcwdu', 'getenv', '_get_exports_list',
'name', 'open', 'pardir', 'path', 'pathsep', 'sep',
'stat_float_times', 'stat_result', 'strerror', 'sys',
'walk'],
overrides={
'access': stubs.fake_access,
'listdir': stubs.RestrictedPathFunction(os.listdir),
# Alias lstat() to stat() to match the behavior in production.
'lstat': stubs.RestrictedPathFunction(os.stat),
'open': stubs.fake_open,
'stat': stubs.RestrictedPathFunction(os.stat),
'uname': stubs.fake_uname,
'getpid': stubs.return_minus_one,
'getppid': stubs.return_minus_one,
'getpgrp': stubs.return_minus_one,
'getgid': stubs.return_minus_one,
'getegid': stubs.return_minus_one,
'geteuid': stubs.return_minus_one,
'getuid': stubs.return_minus_one,
'urandom': stubs.fake_urandom,
'system': stubs.return_minus_one,
},
deletes=['execv', 'execve']),
'signal': ModuleOverridePolicy(overrides={'__doc__': None}),
'locale': ModuleOverridePolicy(
overrides={'setlocale': stubs.fake_set_locale},
default_pass_through=True),
'distutils.util': ModuleOverridePolicy(
overrides={'get_platform': stubs.fake_get_platform},
default_pass_through=True),
# TODO: Stub out imp.find_module and friends.
}
如您所见,os.getuid() 将始终返回 -1:
/tmp/google_appengine$ grep -A1 return_minus_one google/appengine/tools/devappserver2/python/stubs.py
def return_minus_one(*unused_args, **unused_kwargs):
return -1
并且 -1
被转换为 429123195
因为,在 python 源代码 (Modules/pwdmodule.c) 中...
static PyObject *
pwd_getpwuid(PyObject *self, PyObject *args)
{
uid_t uid;
struct passwd *p;
if (!PyArg_ParseTuple(args, "O&:getpwuid", _Py_Uid_Converter, &uid)) {
if (PyErr_ExceptionMatches(PyExc_OverflowError))
PyErr_Format(PyExc_KeyError,
"getpwuid(): uid not found");
return NULL;
}
if ((p = getpwuid(uid)) == NULL) {
if (uid < 0)
PyErr_Format(PyExc_KeyError,
"getpwuid(): uid not found: %ld", (long)uid);
else
PyErr_Format(PyExc_KeyError,
"getpwuid(): uid not found: %lu", (unsigned long)uid);
return NULL;
}
return mkpwent(p);
}
... uid_t 类型转换为 long
截至今天(2016 年 10 月 3 日),google app engine knowledge base文章说(在 Python 部分下):
The system does not allow you to invoke subprocesses, as a result some os module methods are disabled
关于python - 谷歌云存储出现错误 pwd.getpwuid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39823682/
我正在编写一个 shell 脚本来解析当前工作目录的路径(打印当前目录上方的所有基本名称)。 到目前为止,我一直在使用环境变量PWD 来解析路径,但我想知道是否 我可以指望 PWD 始终设置 在每个平
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
我想知道内置pwd和/bin/pwd的代码实现,尤其是当目录路径是符号链接(symbolic link)时。 例子: hita@hita-laptop:/home$ ls -l lrwxrwxrwx
情况是这样的。我有一个电话簿:-%/家/我的名字/ 我在该目录中做了一个软链接(soft link):-%cd/home/我的名字/%ln -s/home/others/. 现在,我从/home/my
我正在从事一个开源项目来跟踪研究事件。在其中一个模块中,我想将文件夹的命令历史记录跟踪到同一文件夹的文件 (.history) 中。 示例: 比方说,我正在处理文件夹 /Users/ravi/test
我开始分析 TI X-Loader,包括它的 makefile。我在顶部的 makefile 中找到了以下几行: TOPDIR := $(shell if [ "$$PWD" != "" ]; the
当我尝试从 cmd 检查我当前的工作目录时,我收到 'pwd' 未被识别为内部或外部命令可操作程序或批处理文件 。 我已经设置了环境变量路径。我仍然遇到这个问题。 ping,cmd 工作正常。 请帮忙
我编写了一个bash文件来自动构建docker镜像并运行docker。构建很好,但是我由于使用$ PWD而收到无效的引用错误。命令如下: #!/bin/bash app="docker.test2"
我是 bash/shell 脚本世界的新手,我正在尝试执行以下操作,它可能非常简单,但我无法弄清楚命令,如果有人能帮助我,那就太好了在这里并指出一些关于 shell 脚本主题的文档。提前谢谢你。 我的
我知道有一个变量 PWD,当我输入命令 cd 时它会被改变。但是当我尝试手动更改它时,当前目录没有改变。如何直接操作PWD? 最佳答案 POSIX describes PWD : Assignment
我在 qmake 项目文件中找到了这一行: DEFINES += SRCDIR=\\\"$$PWD/\\\" 我知道 PWD 部分代表打印工作目录,我让给我 SRCDIR 的值: std::cout
当我使用 chdir() 更改当前工作目录时,为什么 getenv("PWD") 不提供当前工作目录?我还需要 setenv("PWD",newDir,1) 吗? void intChangeDir(
给定 现代 Linux/UNIX/OSX zsh 5+ setopt chase_links PWD没有异常设置 是 [[ "$PWD" == "${${:-.}:A}" ]] 总是正确的? 最佳答案
据我所知,使用 $pwd并使用 ./在 PowerShell 中给出相同的结果。 它们是一样的还是有区别的? 最佳答案 $pwd是一个自动变量。它的名字代表“当前工作目录”,它应该始终包含当前工作路径
我有一个关于为什么会发生这种情况的一般性问题,以及对“pwd”的误解。 您从目录/test 开始,其中有/test/folder1。 文件夹 1 有:file1.txt 在 2 个单独的终端中,我们“
我想在windows下使用docker容器在本地安装OSRM 我按照此 doc 中的步骤进行操作 最后,我无法执行必要的命令,并收到以下错误: 任何建议都会对我很有帮助,谢谢! 最佳答案 每个shel
我 pip install --upgrade google-cloud-storage -t libs 到我的应用引擎应用。 在 appengine_config.py 中,我添加了: vendor
我想在我的应用程序中使用默认用户登录名/密码。 您知道我怎样才能访问这些数据吗? 最好的,帕特里克 最佳答案 如果您尝试在您的应用中使用 Google 身份验证 token ,目前看来是不可能的。有
运行脚本后,我将在当前位置创建一个新文件,然后向该文件添加一些数据:触摸跟踪 DATA=$(密码/跟踪)通过上面的代码,我希望文件位于一般位置,这样即使我与文件不在同一位置,我也可以向其中添加一些数据
这个问题在这里已经有了答案: How to pass command output as multiple arguments to another command (5 个答案) 关闭 5 年前。
我是一名优秀的程序员,十分优秀!