首页 > 解决方案 > 如何解析包含 csv 文件的 Http 请求

问题描述

我正在尝试处理 body 中包含 csv 文件的请求。python3中存在任何提取或解析http请求并获取csv文件的库。我是python的初学者。

我的请求

file = {'file': open('../file/10.csv', 'rb')}
response = requests.post('http://127.0.0.1:8080/function/preprocess', files=file)
print(response.content)

我的处理程序

def handle(event, context):
return {
    "statusCode": 200,
    "body": event.body
}

邮差

---------------------------157082355573515401018537
Content-Disposition: form-data; name="file"; filename="10.csv"
Content-Type: text/csv
id,vendor_id,pickup_datetime,dropoff_datetime,passenger_count,pickup_longitude,pickup_latitude,dropoff_longitude,dropoff_latitude,store_and_fwd_flag,trip_duration
id2875421,2,2016-03-14 17:24:55,2016-03-14 17:32:30,1,-73.982154846191406,40.767936706542969,-73.964630126953125,40.765602111816406,N,455
----------------------------157082355573515401018537--

标签: python-3.x

解决方案


推荐阅读