2017-05-05 2 views
-1

Je veux me connecter à un seau privé s3 et télécharger un csv en python. Comment faire? Je vois beaucoup de commentaires à propos de boto3, donc c'est ce que j'ai essayé et ça échoue.Comment se connecter à S3 en python et télécharger un csv

from boto3.session import Session 
    import pandas as pd 
    import boto3 

    ACCESS_KEY='A' 
    SECRET_KEY='s/' 

    session = Session(aws_access_key_id=ACCESS_KEY, 
       aws_secret_access_key=SECRET_KEY) 
    s3 = session.resource('s3') 

    obj = s3.get_object(Bucket='sp-dps', Key='da-la/hp/hp_co/current') 

    df = pd.read_csv(obj['Body']) 
+0

Veuillez ajouter le message d'exception/d'erreur. – mootmoot

Répondre

0
import boto 
    from boto.s3.key import Key 

    keyId ="xxx" (AWS KEY) 
    sKeyId="yyy" (AWS SECRET KEY ID) 
    srcFileName="/abc/def/ghi/jkl/part_data_1" 
    destFileName="s3_part_data_1.csv" 
    bucketName="s-bucket" 

    conn = boto.connect_s3(keyId,sKeyId) 
    bucket = conn.get_bucket(bucketName) 

    #Get the Key object of the given key, in the bucket 
    k = Key(bucket,srcFileName) 

    #Get the contents of the key into a file 
    k.get_contents_to_filename(destFileName) 

Ce qui précède est le code correct.