简体   繁体   English

Amazon Web Services为什么无法解析我的CloudFront失效批处理请求XML文档?

[英]Why can’t Amazon Web Services parse my CloudFront invalidation batch request XML document?

I'm trying to invalidate some objects I uploaded to Amazon CloudFront using their invalidation API. 我试图使使用其失效API上传到Amazon CloudFront的某些对象失效。

As per their documentation, I'm sending a POST request with an XML document as its content. 根据他们的文档,我正在发送一个带有XML文档作为内容的POST请求。 The XML document specifies the paths to invalidate. XML文档指定要无效的路径。

The error I'm getting back from Amazon is: 我从亚马逊回来的错误是:

<Error>
    <Type>Sender</Type>
    <Code>MalformedInput</Code>
    <Message>Could not parse XML</Message>
</Error>

As far as I can see, my XML document matches their documentation. 据我所知,我的XML文档与他们的文档匹配。

Their documentation: 他们的文件:

My XML document: 我的XML文档:

<InvalidationBatch xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/">
    <Path>/-o-replace.css</Path>
    <Path>/-o-set-link-source.css</Path>

    ...16 other path elements, each containing only letters, numbers, hyphens and periods

    <CallerReference>fixing-accidental-setting-of-gzip-header</CallerReference>
</InvalidationBatch>

I've tried including the XML prolog as they do in their response, keeping and removing whitespace, and leaving out the xmlns attribute, all to no effect. 我已经尝试像在响应中那样包含XML prolog,保留并删除空格,并省略xmlns属性,所有这些都不起作用。

I'm sending the POST request manually using Python. 我正在使用Python手动发送POST请求。 Here's the Python code used to send it. 这是用于发送它的Python代码。 I've confirmed that the file contents are getting read in correctly. 我确认文件内容已正确读取。

from httplib import HTTPSConnection
from datetime import datetime
from hashlib import sha1
import hmac

conneck = HTTPSConnection('cloudfront.amazonaws.com')

invalidation_file = file('invalidation.xml')
invalidation = unicode(invalidation_file.read()).encode('utf-8')

now_as_string = datetime.now().strftime('%a, %d %b %Y %H:%M:%S GMT')
signature = hmac.new('MY_SECRET_KEY', now_as_string, sha1).digest().encode('base64')

conneck.request('POST', '/2010-11-01/distribution/MY_DISTRIBUTION_ID/invalidation', invalidation, {
     'Content-Type': 'text/xml',
    'Authorization': 'AWS MY_ACCESS_KEY_ID' + ':' + signature,
       'x-amz-date': now_as_string,
})

response = conneck.getresponse()

Can anyone see what I'm doing wrong? 谁能看到我在做什么错?

Not an expert with CF APIs, but I think you are doing the base64 encoding wrong, see example: 不是使用CF API的专家,但我认为您在进行base64编码时出错,请参见示例:

>>> 'xyz'.encode('base64')
'eHl6\n'
>>> base64.b64encode('xyz')
'eHl6'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM