Reputation: 166
I attempted to contact Jet directly and was told to “try using 7zip to gzip the file” and then received no further responses (despite further questions).
Here's the error code:
"error_excerpt": [
"Error parsing file: The magic number in GZip header is not correct. Make sure you are passing in a GZip stream."
],
Here's what I'm trying:
def file_upload_url(self, url, filename, data):
headers = {"x-ms-blob-type": "blockblob"}
magic_number = open(filename, 'rb').read(2) # shows that magic number is correct for .gz file
print `magic_number`
with open(filename, 'rb') as f:
file_data=f.read()
response = requests.put(url, headers=headers, files={ "test.json.gz": file_data })
# i've also tried data={"test.json.gz": file_data}
Which then you check with another call. The file was gzipped from the Ubuntu command line (to rule out Python's gzip module causing the problem).
Here is the documentation provided: https://developer.jet.com/docs/
I've implemented every other function without the slightest hiccup but this is just not working. Only thing I can think of is that I'm somehow sending the file data incorrectly. But I can't seem to figure out how.
The .json
file was confirmed to be valid from the Jet representative.
Upvotes: 0
Views: 420
Reputation: 166
Figured out the answer. Must make sure to ONLY put the binary data (not a dictionary, like for files) inside the data parameter in requests.
making it:
def file_upload_url(self, url, filename, data):
headers = {"x-ms-blob-type": "blockblob"}
with open(filename, 'rb') as f:
file_data=f.read()
response = requests.put(url, headers=headers, data=file_data)
Nice and easy.
Upvotes: 2