草庐IT

python - docker内部boto的奇怪行为

coder 2023-05-27 原文

我正在运行以下 image:

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 "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/site-packages/boto/__init__.py", line 141, in connect_s3
    return S3Connection(aws_access_key_id, aws_secret_access_key, **kwargs)
  File "/usr/local/lib/python3.4/site-packages/boto/s3/connection.py", line 190, in __init__
    validate_certs=validate_certs, profile_name=profile_name)
  File "/usr/local/lib/python3.4/site-packages/boto/connection.py", line 569, in __init__
    host, config, self.provider, self._required_auth_capability())
  File "/usr/local/lib/python3.4/site-packages/boto/auth.py", line 987, in get_auth_handler
    'Check your credentials' % (len(names), str(names)))
boto.exception.NoAuthHandlerFound: No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV1Handler'] Check your credentials
>>> 

如果我激活日志记录:

>>> 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, tb, 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 "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/site-packages/boto/__init__.py", line 141, in connect_s3
    return S3Connection(aws_access_key_id, aws_secret_access_key, **kwargs)
  File "/usr/local/lib/python3.4/site-packages/boto/s3/connection.py", line 190, in __init__
    validate_certs=validate_certs, profile_name=profile_name)
  File "/usr/local/lib/python3.4/site-packages/boto/connection.py", line 555, in __init__
    profile_name)
  File "/usr/local/lib/python3.4/site-packages/boto/provider.py", line 200, in __init__
    self.get_credentials(access_key, secret_key, security_token, profile_name)
  File "/usr/local/lib/python3.4/site-packages/boto/provider.py", line 376, in get_credentials
    self._populate_keys_from_metadata_server()
  File "/usr/local/lib/python3.4/site-packages/boto/provider.py", line 391, in _populate_keys_from_metadata_server
    data='meta-data/iam/security-credentials/')
  File "/usr/local/lib/python3.4/site-packages/boto/utils.py", line 394, in get_instance_metadata
    return _get_instance_metadata(metadata_url, num_retries=num_retries, timeout=timeout)
  File "/usr/local/lib/python3.4/site-packages/boto/utils.py", line 234, in _get_instance_metadata
    return LazyLoadMetadata(url, num_retries, timeout)
  File "/usr/local/lib/python3.4/site-packages/boto/utils.py", line 244, in __init__
    data = boto.utils.retry_url(self._url, num_retries=self._num_retries, timeout=self._timeout)
  File "/usr/local/lib/python3.4/site-packages/boto/utils.py", line 224, in retry_url
    boto.log.exception('Caught exception reading instance data')
Message: 'Caught exception reading instance data'
Arguments: ()
2016-01-11 01:53:24,582 boto [ERROR]:Unable to read instance data, giving up
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/site-packages/boto/__init__.py", line 141, in connect_s3
    return S3Connection(aws_access_key_id, aws_secret_access_key, **kwargs)
  File "/usr/local/lib/python3.4/site-packages/boto/s3/connection.py", line 190, in __init__
    validate_certs=validate_certs, profile_name=profile_name)
  File "/usr/local/lib/python3.4/site-packages/boto/connection.py", line 569, in __init__
    host, config, self.provider, self._required_auth_capability())
  File "/usr/local/lib/python3.4/site-packages/boto/auth.py", line 987, in get_auth_handler
    'Check your credentials' % (len(names), str(names)))
boto.exception.NoAuthHandlerFound: No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV1Handler'] Check your credentials
>>> 

(这个例子在我的本地机器上运行)

我已经阅读了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_IDAWS_SECRET_ACCESS_KEY 然后启动 python 来使其工作。不知道这是否有帮助,但我只是想把它扔在那里,因为我花了一些时间看它。

关于python - docker内部boto的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34713189/

有关python - docker内部boto的奇怪行为的更多相关文章

  1. python - 如何使用 Ruby 或 Python 创建一系列高音调和低音调的蜂鸣声? - 2

    关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。

  2. ruby - 如何根据特征实现 FactoryGirl 的条件行为 - 2

    我有一个用户工厂。我希望默认情况下确认用户。但是鉴于unconfirmed特征,我不希望它们被确认。虽然我有一个基于实现细节而不是抽象的工作实现,但我想知道如何正确地做到这一点。factory:userdoafter(:create)do|user,evaluator|#unwantedimplementationdetailshereunlessFactoryGirl.factories[:user].defined_traits.map(&:name).include?(:unconfirmed)user.confirm!endendtrait:unconfirmeddoenden

  3. Python 相当于 Perl/Ruby ||= - 2

    这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Pythonconditionalassignmentoperator对于这样一个简单的问题表示歉意,但是谷歌搜索||=并不是很有帮助;)Python中是否有与Ruby和Perl中的||=语句等效的语句?例如:foo="hey"foo||="what"#assignfooifit'sundefined#fooisstill"hey"bar||="yeah"#baris"yeah"另外,类似这样的东西的通用术语是什么?条件分配是我的第一个猜测,但Wikipediapage跟我想的不太一样。

  4. java - 什么相当于 ruby​​ 的 rack 或 python 的 Java wsgi? - 2

    什么是ruby​​的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht

  5. 华为OD机试用Python实现 -【明明的随机数】 2023Q1A - 2

    华为OD机试题本篇题目:明明的随机数题目输入描述输出描述:示例1输入输出说明代码编写思路最近更新的博客华为od2023|什么是华为od,od薪资待遇,od机试题清单华为OD机试真题大全,用Python解华为机试题|机试宝典【华为OD机试】全流程解析+经验分享,题型分享,防作弊指南华为o

  6. python - 如何读取 MIDI 文件、更改其乐器并将其写回? - 2

    我想解析一个已经存在的.mid文件,改变它的乐器,例如从“acousticgrandpiano”到“violin”,然后将它保存回去或作为另一个.mid文件。根据我在文档中看到的内容,该乐器通过program_change或patch_change指令进行了更改,但我找不到任何在已经存在的MIDI文件中执行此操作的库.他们似乎都只支持从头开始创建的MIDI文件。 最佳答案 MIDIpackage会为您完成此操作,但具体方法取决于midi文件的原始内容。一个MIDI文件由一个或多个音轨组成,每个音轨是十六个channel中任何一个上的

  7. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  8. 「Python|Selenium|场景案例」如何定位iframe中的元素? - 2

    本文主要介绍在使用Selenium进行自动化测试或者任务时,对于使用了iframe的页面,如何定位iframe中的元素文章目录场景描述解决方案具体代码场景描述当我们在使用Selenium进行自动化测试的时候,可能会遇到一些界面或者窗体是使用HTML的iframe标签进行承载的。对于iframe中的标签,如果直接查找是无法找到的,会抛出没有找到元素的异常。比如近在咫尺的例子就是,CSDN的登录窗体就是使用的iframe,大家可以尝试通过F12开发者模式查看到的tag_name,class_name,id或者xpath来定位中的页面元素,会抛出NoSuchElementException异常。解决

  9. python ffmpeg 使用 pyav 转换 一组图像 到 视频 - 2

    2022/8/4更新支持加入水印水印必须包含透明图像,并且水印图像大小要等于原图像的大小pythonconvert_image_to_video.py-f30-mwatermark.pngim_dirout.mkv2022/6/21更新让命令行参数更加易用新的命令行使用方法pythonconvert_image_to_video.py-f30im_dirout.mkvFFMPEG命令行转换一组JPG图像到视频时,是将这组图像视为MJPG流。我需要转换一组PNG图像到视频,FFMPEG就不认了。pyav内置了ffmpeg库,不需要系统带有ffmpeg工具因此我使用ffmpeg的python包装p

  10. Python 刷Leetcode题库,顺带学英语单词(31) - 2

    ValidPalindromeGivenastring,determineifitisapalindrome,consideringonlyalphanumericcharactersandignoringcases. [#125]Example:"Aman,aplan,acanal:Panama"isapalindrome."raceacar"isnotapalindrome.Haveyouconsiderthatthestringmightbeempty?Thisisagoodquestiontoaskduringaninterview.Forthepurposeofthisproblem

随机推荐