Best answer

Use ZIP file in python

  • 3 October 2023
  • 1 reply
  • 97 views

Userlevel 1
Badge

Hi Zapier Community!

Im trying to use a ZIP File that is passing trough a sub-zap and when it goes into th sub-zap looks like: 

 https://zapier.com/engine/hydrate/16299789/.eJxNkduSmkAUR...

 

Then trying to encode in Base64 to pass trough a AWS Lambda Function,  im using this code:

import base64
import urllib

result = []
data = urllib.request.urlopen(input_data['zip_file'])
zip_file = open(data.read(),'rb')
bs64 = base64.b64encode(zip_file.read())
return [{'lines': bs64 }]

But i seems it’s parsing bad the zipfile, get a lot of errors:

 

Your code had an error! Traceback (most recent call last): File "<string>", line 13, in the_function ValueError: embedded null byte

 

How can i do this??

icon

Best answer by greenhub 3 October 2023, 16:33

View original

1 reply

Userlevel 1
Badge

I solved this.

import base64
import urllib.request

zip_url = input_data['zip_file']
with urllib.request.urlopen(zip_url) as response:
zip_file_content = response.read()
bs64 = base64.b64encode(zip_file_content).decode('utf-8')

return [{'base64_zip': bs64}]

Cheers!

Reply