ogre0403 / ipgod

0 stars 3 forks source link

無法辦別下載的檔案名稱或副檔名 #5

Open ogre0403 opened 7 years ago

ogre0403 commented 7 years ago

使用Python requests module下載檔案,需給定儲存的檔案名稱

file_name = abspath + name +"." + fileType.strip(";\"")
with open(file_name, 'wb') as f:
    for chunk in response.iter_content(chunk_size=1024):
        if chunk:
            f.write(chunk)

但有時從http request header無法取到正確檔名/副檔名, 甚至有時open data取下來的資訊裡,file type也不正確。