无法在 Google App Engine 内为 python 应用程序创建配置文件

发布于 2024-09-29 12:50:38 字数 926 浏览 0 评论 0原文

我尝试创建一个配置文件,在其中可以存储常量。

每当我尝试使用 ConfigParser 时,都会收到错误

Traceback (most recent call last):
  File "/home/baun/google_appengine/google/appengine/ext/webapp        /__init__.py", line 511, in __call__
    handler.get(*groups)
  File "/home/baun/workspace/octopuscloud/s3/S3.py", line 138, in get
    test = parser.get('bucket', 'bucketname')
  File "/usr/lib/python2.5/ConfigParser.py", line 511, in get
    raise NoSectionError(section)
NoSectionError: No section: 'bucket'

simple.cfg:

[bucket]
bucketname: 'octopus_storage'

s3.py:

...
from ConfigParser import SafeConfigParser

parser = SafeConfigParser()
parser.read('simple.cfg')

...

# Get values from the config file
test = parser.get('bucket', 'bucketname')
...

如何解决此问题?

===============================

问题已解决。代码是正确的,但 simple.cfg 位于错误的目录中。

I try to create a configuration file, where I can store constants.

Whenever I try with ConfigParser, I get an error

Traceback (most recent call last):
  File "/home/baun/google_appengine/google/appengine/ext/webapp        /__init__.py", line 511, in __call__
    handler.get(*groups)
  File "/home/baun/workspace/octopuscloud/s3/S3.py", line 138, in get
    test = parser.get('bucket', 'bucketname')
  File "/usr/lib/python2.5/ConfigParser.py", line 511, in get
    raise NoSectionError(section)
NoSectionError: No section: 'bucket'

simple.cfg:

[bucket]
bucketname: 'octopus_storage'

s3.py:

...
from ConfigParser import SafeConfigParser

parser = SafeConfigParser()
parser.read('simple.cfg')

...

# Get values from the config file
test = parser.get('bucket', 'bucketname')
...

How can I fix this?

===============================

The problem is fixed. The code was correct, but simple.cfg was in the wrong directory.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

手心的温暖 2024-10-06 12:50:39
[bucket]
bucketname= octopus_storage
[bucket]
bucketname= octopus_storage
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文