简体   繁体   中英

DeserializationError: Cannot deserialize content-type: text/html downloading blob with Python

I have a text file with the names of blob documents I want to download. When I get the first record from the file and try to write it to the output folder, I get the error DeserializationError: Cannot deserialize content-type: text/html.

Now if I just copy the blob reference and do it manually (not reading from the file) it works fine, so not sure what the problem is.

Here is my code:

blob_service_client = BlobServiceClient.from_connection_string(connection_string)
file = open(file_name,"r")
for blob_name in file:
    print(blob_name)
    start = blob_name.find("/ID") + 1
    end = len(blob_name)
    document_name = blob_name[start:end]
    dest_file_name = dest_folder + document_name
    print (dest_file_name)
    container_client = blob_service_client.get_container_client(container_name)
    blob_client = container_client.get_blob_client(blob_name)
    with open(dest_file_name, "wb") as download_file:
        download_file.write(blob_client.download_blob().readall())
    record_count += 1

I found the problem.

I needed to strip the line feed from each value after it is read.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM