【发布时间】:2019-02-04 21:31:20
【问题描述】:
这里有没有人可以帮助我编写这个 python 脚本。
当我执行这个脚本时,我收到了这个错误:
TypeError: request() got an unexpected keyword argument 'json'
import boto3
import requests
from requests_aws4auth import AWS4Auth
host = 'XXXXX' # include https:// and trailing /
region = 'ap-northeast-1'
service = 'es'
credentials = boto3.Session().get_credentials()
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token)
# Register repository
headers = {"Content-Type": "application/json"}
path = '_snapshot/XXXXX' # the Elasticsearch API endpoint
url = host + path
payload = {
"type": "s3",
"settings": {
"bucket": "XXXXX",
"region": "ap-northeast-1",
"role_arn": "XXXXX"
}
}
r = requests.put(url, auth=awsauth, json=payload, headers=headers)
print(r.status_code)
print(r.text)
【问题讨论】:
-
json 不是 put 方法的参数。使用的正确参数是 data
-
我试过了,但它返回了这个错误:{"Message":"Your request: '/_snapshot/CuratorRepo' is not allowed due to invalid input parameters."}
标签: python json amazon-web-services amazon-s3 amazon-elasticsearch