Skip to content

Instantly share code, notes, and snippets.

@olmosleo
Created September 23, 2020 17:15
Show Gist options
  • Save olmosleo/6667baf251196b5f2018c25f02941064 to your computer and use it in GitHub Desktop.
Save olmosleo/6667baf251196b5f2018c25f02941064 to your computer and use it in GitHub Desktop.
Python Script Read CVS to PUT API REST AUTH_BASIC CALL
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