我正在尝试在 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/