2017-02-28 2 views
0

Ich versuche, Batch-Prozesse von AWS Machine Learning aus einem Python-Projekt zu verwenden. Ich benutze Boto3. Ich bekomme diese Fehlermeldung in der Antwort.Python-Aufruf an boto3.client.create_data_source_from_s3

Es gab einen Fehler versucht, das Schema zu analysieren: \ 'nicht Instanz boolean aus START_ARRAY Token \ n an [Quelle deserialisieren kann: [email protected]; Zeile: 1, Spalte: 2] (durch Referenz Kette: com.amazon.eml.dp.recordset.SchemaPojo [ "dataFileContainsHeader"]) \

Die CSV-Datei I Arbeiten verwenden. Ich weiß das, weil es durch den Konsolenprozess funktioniert hat.

Hier ist mein Code; es ist eine Funktion innerhalb eines django-Modell, das die URL der Datei hält an (input_file) verarbeitet werden:

def create_data_source_from_s3(self): 
     attributes = [] 
     attribute = { "fieldName": "Var1", "fieldType": "CATEGORICAL" } 
     attributes.append(attribute) 
     attribute = { "fieldName": "Var2", "fieldType": "CATEGORICAL" } 
     attributes.append(attribute) 
     attribute = { "fieldName": "Var3", "fieldType": "NUMERIC" } 
     attributes.append(attribute) 
     attribute = { "fieldName": "Var4", "fieldType": "CATEGORICAL" } 
     attributes.append(attribute) 
     attribute = { "fieldName": "Var5", "fieldType": "CATEGORICAL" } 
     attributes.append(attribute) 
     attribute = { "fieldName": "Var6", "fieldType": "CATEGORICAL" } 
     attributes.append(attribute) 

     dataSchema = {} 
     dataSchema['version'] = '1.0' 
     dataSchema['dataFormat'] = 'CSV' 
     dataSchema['attributes'] = attributes 
     dataSchema["targetFieldName"] = "Var6" 
     dataSchema["dataFileContainsHeader"] = True, 
     json_data = json.dumps(dataSchema) 

     client = boto3.client('machinelearning', region_name=settings.region, aws_access_key_id=settings.aws_access_key_id, aws_secret_access_key=settings.aws_secret_access_key) 
     #create a datasource 
     return client.create_data_source_from_s3(
      DataSourceId=self.input_file.name, 
      DataSourceName=self.input_file.name, 
      DataSpec={ 
       'DataLocationS3': 's3://' + settings.AWS_S3_BUCKET_NAME + '/' + self.input_file.name, 
       'DataSchema': json_data, 
      }, 
      ComputeStatistics=True 
      ) 

Alle Ideen, was ich falsch mache?

Antwort

2

das Komma entfernen

dataSchema["dataFileContainsHeader"] = True, 

Dieser Python, dass Sie ein Tupel hinzufügen zu denken verursacht. Also Ihr dataSchema enthält tatsächlich (True,)

und die Ausgabe wie folgt aussieht

{"dataFileContainsHeader": [true], "attributes": [{"fieldName": "Var1", "fieldType": "CATEGORICAL"}, {"fieldName": "Var2", "fieldType": "CATEGORICAL"}, {"fieldName": "Var3", "fieldType": "NUMERIC"}, {"fieldName": "Var4", "fieldType": "CATEGORICAL"}, {"fieldName": "Var5", "fieldType": "CATEGORICAL"}, {"fieldName": "Var6", "fieldType": "CATEGORICAL"}], "version": "1.0", "dataFormat": "CSV", "targetFieldName": "Var6"} 

AWS stattdessen etwas erwartet wie diese

"dataFileContainsHeader": true