Created
September 23, 2020 17:15
-
-
Save olmosleo/6667baf251196b5f2018c25f02941064 to your computer and use it in GitHub Desktop.
Python Script Read CVS to PUT API REST AUTH_BASIC CALL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import csv | |
import json | |
# Read CSV file | |
print('[Read] CVS Files') | |
with open("_NAME_FILE_.csv") as fp: | |
reader = csv.reader(fp, delimiter=",", quotechar='"') | |
# next(reader, None) # skip the headers | |
data_read = [row for row in reader] | |
#print(type(data_read)) | |
#print(data_read[0]) | |
for x in data_read: | |
print ('[email] -> ' + x[0] + '| [BS] -> ' + x[1]) | |
payload = {"attributes":[{ "name": "BS", "values": [ x[1] ] }]} | |
headers = {'content-type': 'application/json'} | |
r = requests.post('https://_API_URL/attribute?username='+x[0], data=json.dumps(payload), headers=headers, auth=('API_USER_AUTH', 'API_PASS_AUTH')); | |
print(r.status_code) | |
# print(r.encoding) | |
print(r.text) | |
# r = requests.get('https://_API_URL/user?username=_EMAIL&expand=attributes', auth=('API_USER_AUTH', 'API_PASS_AUTH')); | |
#r.text | |
#r.json() | |
#payload = {"attributes":[{ "name": "BS", "values": [ "11111111111"] }]} | |
#headers = {'content-type': 'application/json'} | |
#r = requests.post('https://_API_URL/attribute?username=_EMAIL', data=json.dumps(payload), headers=headers, auth=('API_USER_AUTH', 'API_PASS_AUTH')); | |
#print(r.status_code) | |
# print(r.encoding) | |
#print(r.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment