Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Downloaded file corrupted
#6
emont Wrote:That would be the problem, that URL cannot accessed from Internet but an Intranet.
Ok,to look a little more at this,dos file_2b_downloaded give you the real download link?
To give a example,you should test like this no loop or other stuff,just test the download.
Sample zip files download
import requests

url = 'https://drive.google.com/uc?export=download&id=1o9DtaYEb1N-C_L7kqCAgfE0D5RaEwbZH'
response = requests.get(url)
with open('5mb.zip', 'wb') as f:
    f.write(response.content)
So this works now because here i use the real download link,for the 5 mb sample zip file.

If parse out the link,look like this
import requests
from bs4 import BeautifulSoup

url = 'https://web-utility.com/en/sample/files/sample-zip-file-download'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'lxml')
link = soup.select_one('div.col-md-3.col-3.text-right > a').get('href')
response = requests.get(link)
with open('5mb.zip', 'wb') as f:
    f.write(response.content) 
So this is a simpler case because download link is exposed and all can see it.
One more here i look at what is send over network Chrome dev-tool(inspect -> network),sometime can need to do this.
import requests

headers = {
    'authority': 'drive.google.com',
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
}

params = {
    'export': 'download',
    'id': '1o9DtaYEb1N-C_L7kqCAgfE0D5RaEwbZH',
}

response = requests.get('https://drive.google.com/uc', params=params, headers=headers)
with open('5mb.zip', 'wb') as f:
    f.write(response.content)
Also some cases can be using Selenium be easier,as if have to press a button before get the real download address.
Reply


Messages In This Thread
Downloaded file corrupted - by emont - Sep-30-2023, 02:20 AM
RE: Downloaded file corrupted - by buran - Sep-30-2023, 05:10 AM
RE: Downloaded file corrupted - by emont - Sep-30-2023, 01:15 PM
RE: Downloaded file corrupted - by snippsat - Sep-30-2023, 01:21 PM
RE: Downloaded file corrupted - by emont - Sep-30-2023, 11:34 PM
RE: Downloaded file corrupted - by snippsat - Oct-01-2023, 11:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I downloaded a script and I cant run this luoxr18 3 1,250 Apr-16-2023, 09:33 AM
Last Post: Larz60+
Sad pandas writer create "corrupted" file freko75 1 2,868 Jun-14-2022, 09:57 PM
Last Post: snippsat
  Structuring and pivoting corrupted dataframe in pandas gunner1905 2 2,283 Sep-18-2021, 01:30 PM
Last Post: gunner1905
  How to create local copies of Python packages so they do not have to be downloaded okhajut 3 2,054 Sep-29-2020, 02:22 PM
Last Post: buran
  Error in Python3.6:free() Corrupted unsorted chunks error sameer_k 2 3,920 Mar-18-2020, 09:37 AM
Last Post: sameer_k
  How to create an environment for program downloaded from github StartedNewLife 3 2,216 Jan-25-2020, 06:34 PM
Last Post: ibreeden
  Multiprocessing.Queue Issues (Missing/Corrupted Items/No Output) python3noob 0 3,236 Aug-03-2019, 09:38 PM
Last Post: python3noob
  Why the file is not downloaded in full with this script? Jacklops 2 2,730 Jan-07-2019, 09:33 AM
Last Post: DeaD_EyE
  PyPDF2 Hanging When Trying to Open Corrupted PDF bmccollum 6 8,851 Nov-09-2018, 10:40 AM
Last Post: Larz60+
  importing downloaded usb module kiyoshi7 5 4,482 Apr-29-2018, 06:44 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020