我正在尝试遍历 CSV 并运行 Web 请求。我无法让它超过 CSV 中的第一行。
CSV 正在从 Mac Excel 导出为 10 行/1 列中的 10 个项目的列表。
def AddTokens(request):
import csv
tokenList = []
output = 0
apikey = "12345"
restkey = "12345"
URL = "https://api.web.com/1/install/"
headers = {'content-type': 'application/json', 'X-web-Application-Id': apikey, 'X-web-REST-API-Key': restkey}
with open('/Users/name/Desktop/test.csv', 'rU') as csvfile:
deviceTokens = csv.reader(csvfile, delimiter=',')
for token in deviceTokens:
deviceToken = token[0].replace("/", "")
deviceType = "ios"
pushToken = "pushtoken_" + deviceToken
payload = {"deviceType": deviceType, "deviceToken": deviceToken, "channels": ["", pushToken]}
r = requests.post(URL, data=json.dumps(payload), headers=headers)
t = get_template('addpush.html')
html = t.render(Context({'output': output, 'tokenList': tokenList, 'deviceTokens': deviceTokens, 'token': token}))
return HttpResponse(html)