I need to send csv file as input in the request along with url,data & headers as this is import request. But the Request is not supporting the files. Can you assist me how to send files input in the urllib.request.
headers = { 'SESSION-ID': 'xxx', 'keyid': 'xxx' }
payload = {"delimiter":"COMMA","textQualifier":"DOUBLE_QUOTE","codepage":"UTF8",
"dateFormat":"ISO"}
payload1 = json.dumps(payload).encode("utf-8")
payload2 = {'importSettings':payload1}
data = json.dumps(payload2).encode("utf-8")
#print(data)
files = [('file',('import.csv', csvstr,'text/csv'))]
url = xxx
try:
req = urllib.request.Request(url, data, headers,files=files)
with urllib.request.urlopen(req) as f:
res = f.read()
print(res.decode())
return res
except Exception as e:
print(e)
Getting this error - init() got an unexpected keyword argument 'files'