0

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'

saminfa
  • 11
  • 1
  • 6
  • For some reason, I am getting SSL error when I am using requests. So I replaced the request with urllib.request. (SSL error link => https://stackoverflow.com/questions/66653440/httpsconnectionpoolhost-port-443-max-retries-exceeded-with-url-caused-b?noredirect=1#comment117853301_66653440) . – saminfa Apr 07 '21 at 12:50
  • yes.I did. But It did not resolve the SSL error. Is there a way to send files as one of the input with Urllib.request. – saminfa Apr 07 '21 at 13:41
  • ok thanks. Let me check it. – saminfa Apr 07 '21 at 14:44

0 Answers0