如何从csv数据循环HTTPS requests.post

如何从csv数据循环HTTPS requests.post,https,python-requests,Https,Python Requests,我想循环从csv发送数据的post请求 csv文件(有2列)= agentLicenseID(x)licenseExpirationDate(y) 271844 6/20/2021 271847 6/30/2021 271848 5/21/2021 body={'sid':API_-sid,'key':API_-key,'agentLicenseID':x,'licenseExpirationDate':y} response=requests.post(url=UPD\uurl,dat

我想循环从csv发送数据的post请求

csv文件(有2列)=

agentLicenseID(x)licenseExpirationDate(y)
271844  6/20/2021
271847  6/30/2021
271848  5/21/2021
body={'sid':API_-sid,'key':API_-key,'agentLicenseID':x,'licenseExpirationDate':y}
response=requests.post(url=UPD\uurl,data=body)

我打算在pandas的帮助下,从csv文件中循环响应不同的x和y值(agentLicenseID和licenseExpirationDate):

import pandas as pd


df = pd.read_csv("your_file.csv", sep=r"\s+")  # <-- change the separator if it's different

for x, y in zip(df["agentLicenseID"], df["licenseExpirationDate"]):
    body = {
        "sid": API_SID,
        "key": API_KEY,
        "agentLicenseID": x,
        "licenseExpirationDate": y,
    }
    response = requests.post(url=UPD_URL, data=body)

    # ...
将熊猫作为pd导入

df=pd.read_csv(“your_file.csv”,sep=r“\s+”)#谢谢,我现在明白逻辑了。然而,我似乎仍然得到一个错误:KeyError:'agentLicenseID'。你知道这可能是什么原因吗?你认为这与系统如何读取csv有关吗?在定义变量(pd.read.csv)后,我调用了df,得到了以下输出:agentLicenseID,licenseExpirationDate 0 271844,3/12/2021 1 1 271847,6/22/2021 2 271848,5/5/2021实际上刚刚计算出来,问题在于分隔符,需要将其更改为“,”。非常感谢,非常感谢!