[Python] passing a csv through an API

Discussão em 'Python' iniciado por Stack, Fevereiro 10, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to pass a csv through an api like this:

    The csv is as follow:

    field_1, field_2, field_3
    1, 3, 7


    the push code is this:

    with open("sample_csv.csv") as f:
    data = {"file": f}
    print(data)
    headers = {
    "Content-Type": "text/csv",
    "File-Type": "POS",
    "File-Key": "somekey",
    }

    r = requests.post(endpoint, data=data, headers=headers)


    However when i read it from a Lambda on the other end i get this:

    b'file=field_1%2C+field_2%2C+field_3%0A&file=1%2C+3%2C+7'


    When i run the above string through chardet it tells me its ascii, but i dont know how to convert it


    edit: lambda function code:

    def main(event: dict, context) -> dict:
    body = base64.b64decode(event["body"])
    print(body)

    Continue reading...

Compartilhe esta Página