Python CURL 删除请求函数

标签 python csv curl python-requests

我正在尝试在 Python 中重新创建此 CURL 请求并让它循环遍历 CSV。

curl -X "DELETE" --user 'api:<my-api-key>' \   https://api.mailgun.net/v3/messages.thewebsite/unsubscribes \  
-F address='email@gmail.com'
我想我应该创建一个函数并返回结果。我正在使用请求包和 CSV 但得到的输出
打印到控制台。我在这里缺少什么?
下面的代码示例。
Import csv
Import requests


def remove_suppression():
    return requests.delete(
        "https://api.mailgun.net/v3/messages.thewebsite.com/unsubscribes",
        auth=("api", "key-abcdefg12345789gbb"),
        data={'address':'row[1]'})

with open('/Users/brett/Downloads/example.csv',newline='') as csvfile:
    readCSV = csv.reader(csvfile, delimiter=',')
    for row in readCSV:
            try:
                
                remove_suppression()
                print("=========================")
                print(remove_suppression.text)
                sleep(5)
 
            except:

            #write log to a text file

最佳答案

您需要通过 row值作为 remove_supression 的参数.目前您正在打印 remove_suppression 的值,这是一个函数。
您应该将函数的顶部替换为:

def remove_supression(row): ...
确保同时更换 'row[1]'部分只是 row , 否则你只是发送文字字符串 'row[1]'而不是实际的行。
最重要的是,您需要分配从 remove_supression(row) 获得的值。在 for 循环中指向一个值,然后您可以使用该值从中获取文本,例如:
resp = remove_supression(row)
print(resp.text)

关于Python CURL 删除请求函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69457949/

相关文章:

javascript - csv格式问题javascript p5

python - xls Python 的元组列表

python - 在数据帧上应用 python-geohash 编码函数

python - django-simple-captcha 破坏 Heroku 部署

python - 如何在 Python 中连接两个数据框?

php - 避免 cURL 调用之间的网络问题

api - 使用 bash curl 和 oauth 返回谷歌应用程序用户帐户数据?

python - 多个处理器记录到同一个旋转文件

打印到 CSV 时 Python 跳过行

linux - 何时以及何时不在 Docker Remote API 中使用 tty