2

I am trying to upload a package binary over to the RestAPI of storage using python. But it keeps throwing error and couldn't upload the file. Below is the code I am using to achieve it :

jsonheaderup={'Content-Type': 'application/octet-stream'}

file = open('install.pkg.gz', 'rb')
files = {'file': file}

def upload_code():

  u = requests.post("%s/api/sys/v2/updates" % (url), files=files, verify=False,      headers=jsonheaderup)
  l = json.loads(u.text)

upload_code()
4
  • I tried to change the jsonheader file type to application/x-gzip . But now it gives an argument error, even though everything is present : Error : {u'fault': {u'message': u'required input argument is missing (upload)', u'code': 400, u'name': u'ERR_MISSING_ARG'}} Commented Sep 12, 2018 at 10:38
  • Just wondering ... Why the zfs tag? Commented Sep 13, 2018 at 7:48
  • And BTW, if you have more info, like your first comment, you can edit your original post to include it. Commented Sep 13, 2018 at 7:50
  • zfs tag as I am trying to access the RestAPI of a ZFSSA Commented Sep 14, 2018 at 4:15

2 Answers 2

3

The earlier posts didn't really helped but I figured it out by referring the original doc of requests: Streaming uploads. Check doc here.

As my file was huge around 1.9 GB, so session was breaking in between the upload process, hence giving error as "Internal error".

As its huge file I streamed and upload it by providing a file-like object in my function:

def upload_code():
  jsonheaderup={'Content-Type': 'application/octet-stream'}
  with open('/root/ak-nas-2013-06-05-7-18-1-1-3-nd.pkg.gz', 'rb') as file:
    requests.post("%s/api/system/v1/updates" % (url), data=file, auth=zfsauth, verify=False, headers=jsonheaderup, timeout=None)
Sign up to request clarification or add additional context in comments.

Comments

0

At first glance, I can not see any mistake.

Did you see this: Python 3 script to upload a file to a REST URL (multipart request) ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.