【问题标题】:400 Bad Request while pulling instances with amazon使用亚马逊拉取实例时出现 400 错误请求
【发布时间】:2012-04-09 07:31:38
【问题描述】:

任何人都可以说出我为什么会收到此错误吗?

我在连接到亚马逊服务器后拉取实例时遇到了这个问题。

import boto

con = boto.connect_ec2(aws_access_key_id='XXX',aws_secret_access_key='XXX')
con.get_all_instances()

Traceback (most recent call last):

  File "getAllinstanc.py", line 7, in <module>

    reservations = ec2conn.get_all_instances()

  File "c:\jiva\py26\lib\site-packages\boto-2.3.0-py2.6.egg\boto\ec2\connection.py", line 467, in get_all_instances

    [('item', Reservation)], verb='POST')
  File "c:\Jiva\py26\lib\site-packages\boto-2.3.0-py2.6.egg\boto\connection.py", line 896, in get_list

    raise self.ResponseError(response.status, response.reason, body)

boto.exception.EC2ResponseError: EC2ResponseError: 400 Bad Request

<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>RequestExpired</Code><Message>Request has expired. Timestamp date is 2012-04-09T06:54:53Z</Message></Error></Errors><RequestID>44
08be18-5d2b-420b-af48-e2cb03</RequestID></Response>

【问题讨论】:

    标签: boto


    【解决方案1】:

    boto(或任何其他 AWS 客户端库)发出的每个请求都经过加密签名,并具有与之关联的时间戳(通常是请求中的 Date 标头)。时间戳必须与亚马逊对当前时间的想法相当接近,通常在 15 分钟内。如果时间戳超出此可接受的窗口,您将收到类似这样的错误。

    因此,简短的回答是检查客户端计算机上的系统时间。它似乎不准确。

    【讨论】:

    • 如果我的系统时间已关闭,我会收到 401 Unauthorized,而不是 400 --boto.exception.EC2ResponseError: EC2ResponseError: 401 Unauthorized
    【解决方案2】:

    Amazon's forum 上描述的时钟偏差有很好的测试方法。

    类型:

    wget -S  "https://email.us-east-1.amazonaws.com"
    

    这会返回错误,但会在 Date 标头中包含远程系统的时间。然后将其与系统上 date 的结果进行比较(假设它是 unix 派生的)。

    如果您的操作系统恰好是 Ubuntu 或其他 Debian 变体,您可以通过安装这样的 ntp 守护程序来保持时间最新:

    sudo apt-get install ntp
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-08
      • 2017-04-12
      • 1970-01-01
      • 2014-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多