簡體   English   中英

Amazon Web Services為什么無法解析我的CloudFront失效批處理請求XML文檔?

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

我試圖使使用其失效API上傳到Amazon CloudFront的某些對象失效。

根據他們的文檔,我正在發送一個帶有XML文檔作為內容的POST請求。 XML文檔指定要無效的路徑。

我從亞馬遜回來的錯誤是:

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

據我所知,我的XML文檔與他們的文檔匹配。

他們的文件:

我的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>

我已經嘗試像在響應中那樣包含XML prolog,保留並刪除空格,並省略xmlns屬性,所有這些都不起作用。

我正在使用Python手動發送POST請求。 這是用於發送它的Python代碼。 我確認文件內容已正確讀取。

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()

誰能看到我在做什么錯?

不是使用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