python - Google App Engine dev_appserver.py 导入 apache_beam 时出现 IOError

标签 python google-app-engine apache-beam

我有一个 App Engine 应用程序,它打破了我的习惯

import apache_beam

我可以确认依赖项已安装在应用程序运行的虚拟环境中。从下面的堆栈跟踪来看,它似乎出于某种原因尝试访问/dev/null,但失败了。

INFO     2017-08-13 13:03:37,980 stubs.py:50] Sandbox prevented access to file "/home/raul/Downloads/google-cloud-sdk"
INFO     2017-08-13 13:03:37,980 stubs.py:51] If it is a static file, check that `application_readable: true` is set in your app.yaml
INFO     2017-08-13 13:03:37,980 stubs.py:50] Sandbox prevented access to file "/home/raul/Downloads/google-cloud-sdk/platform"
INFO     2017-08-13 13:03:37,980 stubs.py:51] If it is a static file, check that `application_readable: true` is set in your app.yaml
INFO     2017-08-13 13:03:38,260 stubs.py:50] Sandbox prevented access to file "/dev/null"
INFO     2017-08-13 13:03:38,260 stubs.py:51] If it is a static file, check that `application_readable: true` is set in your app.yaml
ERROR    2017-08-13 13:03:38,261 wsgi.py:263] 
Traceback (most recent call last):
  File "/home/raul/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/home/raul/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/home/raul/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/home/raul/Documents/football/main.py", line 7, in <module>
    import apache_beam
  File "/home/raul/Documents/football/env/lib/python2.7/site-packages/apache_beam/__init__.py", line 75, in <module>
    import apache_beam.internal.pickler
  File "/home/raul/Documents/football/env/lib/python2.7/site-packages/apache_beam/internal/pickler.py", line 38, in <module>
    import dill
  File "/home/raul/Documents/football/env/lib/python2.7/site-packages/dill/__init__.py", line 27, in <module>
    from .dill import dump, dumps, load, loads, dump_session, load_session, \
  File "/home/raul/Documents/football/env/lib/python2.7/site-packages/dill/dill.py", line 165, in <module>
    FileType = type(open(os.devnull, 'rb', buffering=0))
  File "/home/raul/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/stubs.py", line 260, in __init__
    raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: '/dev/null'

有什么想法可能导致此问题以及如何解决它吗?

最佳答案

GAE Python sandbox就允许您的应用程序代码执行的操作而言,这是相当严格的。看起来 apache-beam 使用的 dill 包需要访问特殊文件(在本例中为 /dev/null 设备文件)沙箱上不允许。

您可以更改代码以满足所有沙箱要求,或者尝试使用 the flexible environment ,它的容忍度要高得多(但总体来说它是一个不同的野兽)。请参阅Choosing an App Engine EnvironmentMigrating Services from the Standard Environment to the Flexible Environment .

旁注:回溯表明您的应用程序尝试从本地系统安装执行 apache-beam,这在标准环境中也不起作用 - 它需要供应到您的应用程序中,请参阅 Installing a third-party library .

关于python - Google App Engine dev_appserver.py 导入 apache_beam 时出现 IOError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45660772/

相关文章:

python - Django 中所有 Celery worker/内存缓存的全局可访问对象

google-app-engine - 文件不可访问 : 'templates/test.html' using jinja2 templates in certain directories

google-app-engine - 从 Appengine 连接到来自 Google Containers 的 Kubernetes 服务

python - Django 管理员的有效用例?

python - 为什么 Python argparse 中的 fromfile-prefix-chars 不起作用?

python - Eclipse + Pydev + twitter 库问题

iphone - 从 Google App Engine 的数据存储中获取实体以用于 iOS 应用

python-3.x - 使用 Apache Beam Python 为每个窗口编写唯一的 Parquet 文件

java - 使用 Apache Beam 将重复的字符串写入 BigQuery

python - Dataflow 中的自定义 Apache Beam Python 版本