我尝试使用以下代码将密钥导入API网关
import boto3, hashlib, random, csv
apigateway = boto3.client('apigateway')
apikey = 'test'
with open('/tmp/apikey.csv', 'wb') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
filewriter.writerow(['Name', 'Key', 'Enabled', 'usageplanIds'])
filewriter.writerow(['testkey', apikey, 'TRUE', '963uwo'])
response = apigateway.import_api_keys(
body='/tmp/apikey.csv',
format='csv',
failOnWarnings=False
)
然而,这给了我
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 312, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 601, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.BadRequestException: An error occurred (BadRequestException) when calling the ImportApiKeys operation: Missing required column 'Key'
我还尝试直接复制http://docs.aws.amazon.com/apigateway/latest/developerguide/api-key-file-format.html中给出的示例,但仍然会得到相同的错误,即使Key已明确设置。
这是我的/tmp/apikey.csv
jonathan@ubuntu ~> cat /tmp/apikey.csv
Name,Key,Enabled,usageplanIds
testkey,test,TRUE,963uwo
jonathan@ubuntu ~>
答案 0 :(得分:3)
您提供了body='/tmp/apikey.csv
&#39;但是import_api_keys API期望body是字节或可搜索文件类对象。您错误地提供了文件名。