2017-09-27 4 views
0

나는 내게했습니다Boto3 누락 필요한 열 '키'오류

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' 

을 제공

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 
) 

그러나 다음 코드를 사용하여 API 게이트웨이에 키를 가져하려고 해요 http://docs.aws.amazon.com/apigateway/latest/developerguide/api-key-file-format.html에있는 예제를 직접 복사하려고했으나 Key가 명확하게 설정되어 있어도 여전히 동일한 오류가 발생합니다.

다음은 'body='/tmp/apikey.csv을 제공 한 내 /tmp/apikey.csv

[email protected] ~> cat /tmp/apikey.csv 
Name,Key,Enabled,usageplanIds 
testkey,test,TRUE,963uwo 
[email protected] ~> 
+0

바이너리 라인을 작성하지 않고 인터프리터가'mode = 'wb''을 좋아하지 않는다는 사실 외에도'filewriter = csv.writer (csvfile, delimiter = ',', lineterminator = ', \ n ')'? – Uvar

+0

가 작동하지 않아 CSV 파일을 포함하도록 질문을 업데이트했습니다. – Jonathan

답변

3

입니다하지만 import_api_keys API는 몸이 바이트 검색 가능한 파일 - 류의 객체이 될 것으로 기대하고있다. 파일 이름을 잘못 입력했습니다.