加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

python – 在docker中boto的奇怪行为

发布时间:2020-12-16 03:35:21 所属栏目:安全 来源:网络整理
导读:我正在运行以下图像: docker run -it --rm python:3.4-slim /bin/bash 在它里面(作为root),我安装了: root@dab02ca9c61d:~# apt-get update apt-get install nano 然后是boto root@dab02ca9c61d:~# pip install boto 然后我在/root/.boto中写了以下内容:

我正在运行以下图像:

docker run -it --rm python:3.4-slim  /bin/bash

在它里面(作为root),我安装了:

root@dab02ca9c61d:~# apt-get update && apt-get install nano

然后是boto

root@dab02ca9c61d:~# pip install boto

然后我在/root/.boto中写了以下内容:

[Credentials]
aws_access_key_id = some_long_string
aws_secret_access_key = another_bigger_string

[Boto]
debug = 2
num_retries = 10

(此文件与我在主机中的文件相同)

版本是:

root@dab02ca9c61d:~# python -V
Python 3.4.4
root@dab02ca9c61d:~# pip list
boto (2.38.0)
pip (7.1.2)
setuptools (18.2)
root@dab02ca9c61d:~# 

(与我在主机/本地机器上完全相同)

如果我解雇了python控制台:

root@dab02ca9c61d:~# python
Python 3.4.4 (default,Jan  8 2016,00:24:55) 
[GCC 4.9.2] on linux
Type "help","copyright","credits" or "license" for more information.
>>> import boto
>>> boto.connect_s3()
Traceback (most recent call last):
  File "

如果我激活日志记录:

>>> boto.set_stream_logger('boto')
>>> boto.connect_s3()                                                                                                                                                                                                
2016-01-11 01:53:23,577 boto [DEBUG]:Using access key found in config file.
2016-01-11 01:53:23,577 boto [DEBUG]:Using secret key found in config file.
2016-01-11 01:53:23,577 boto [DEBUG]:Retrieving credentials from metadata server.
--- Logging error ---
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/logging/__init__.py",line 978,in emit
    msg = self.format(record)
  File "/usr/local/lib/python3.4/logging/__init__.py",line 828,in format
    return fmt.format(record)
  File "/usr/local/lib/python3.4/logging/__init__.py",line 573,in format
    record.exc_text = self.formatException(record.exc_info)
  File "/usr/local/lib/python3.4/logging/__init__.py",line 523,in formatException
    traceback.print_exception(ei[0],ei[1],tb,None,sio)
  File "/usr/local/lib/python3.4/traceback.py",line 169,in print_exception
    for line in _format_exception_iter(etype,value,limit,chain):
  File "/usr/local/lib/python3.4/traceback.py",line 146,in _format_exception_iter
    for value,tb in values:
  File "/usr/local/lib/python3.4/traceback.py",line 125,in _iter_chain
    context = exc.__context__
AttributeError: 'NoneType' object has no attribute '__context__'
Call stack:
  File "

(此示例在我的本地计算机中运行)

我已经阅读了Boto Credential Error with Python on Windows Boto: Dynamically get aws_access_key_id and aws_secret_access_key in Python code from config?和另一个问题.什么都行不通.

之后,我查看了boto.pyami的源代码,如果我逐行执行什么都没有.

例如:

>>> boto.config.sections()
['Credentials','Boto']
>>> boto.config.get_value('Credentials','aws_access_key_id')
>>> 

请注意,最后一个命令返回None.

boto.config使用ConfigParser,如果我使用它,它的工作原理:

>>> import configparser
>>> config = configparser.ConfigParser()
>>> config.read('~/.boto')
[]
>>> config.read('/root.boto')                                         
['/root/.boto']
>>> config.get('Credentials','aws_access_key_id')
'some_long_string'
>>> 

(注意,如果我使用相对路径它不起作用)

最后,如果我使用:

>> boto.connect_s3('some_long_string','another_bigger_string')
2016-01-11 02:05:33,636 boto [DEBUG]:Using access key provided by client.
2016-01-11 02:05:33,636 boto [DEBUG]:Using secret key provided by client.
S3Connection:s3.amazonaws.com
>>> 

我做了另一个测试:我安装了awscli并且没有问题,将配置文件放在/etc/boto.cfg中并且不起作用.

我已经在这周末度过了所有的想法吗?

最佳答案
由于我不能发表评论,我会把它作为答案,但不完全确定Docker的问题是什么,但我也能够复制问题.可能想在boto上发一个问题,看看有人可以提供帮助.但是,我能够通过设置环境变量AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY然后启动python来使其工作.不知道这是否有所帮助,但只是想把它扔出去,因为我花了一些时间来看它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读