Every line of 'python requests download image' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
184 def download_image(self, img_url): 185 """ Downloads a single image. 186 187 Downloads img_url using self.page_url as base. 188 Also, raises the appropriate exception if required. 189 """ 190 img_request = None 191 try: 192 img_request = requests.request( 193 'get', img_url, stream=True, proxies=self.proxies) 194 if img_request.status_code != 200: 195 raise ImageDownloadError(img_request.status_code) 196 except: 197 raise ImageDownloadError() 198 199 if img_url[-3:] == "svg" or (int(img_request.headers['content-length']) > self.min_filesize and\ 200 int(img_request.headers['content-length']) < self.max_filesize): 201 img_content = img_request.content 202 with open(os.path.join(self.download_path, img_url.split('/')[-1]), 'wb') as f: 203 byte_image = bytes(img_content) 204 f.write(byte_image) 205 else: 206 raise ImageSizeError(img_request.headers['content-length']) 207 return True
19 def download_image(url, savepath): 20 response = requests.get(url, headers=headers, stream=True) 21 with open(savepath, 'wb') as out_file: 22 shutil.copyfileobj(response.raw, out_file)
14 def download(self, url): 15 response = self.session.get(url) 16 return response.content
89 def download_image(image_url, path='./'): 90 if not image_url: 91 return None 92 image_path = create_file_name(path) 93 urllib.request.urlretrieve(image_url, image_path) 94 # did download succeed? 95 if os.path.isfile(image_path): 96 return image_path 97 else: 98 return None
71 def download_image(url): 72 name = random.randrange(1,100000) 73 fullname = '/tmp/' + str(name) + ".png" 74 urllib.request.urlretrieve(url, fullname) 75 return fullname
80 def downloadImage(url): 81 if not url: 82 return None 83 84 try: 85 img, _ = urllib.request.urlretrieve(url) 86 except Exception: 87 return None 88 ext = imghdr.what(img) 89 res = img + "." + ext 90 os.rename(img, res) 91 92 # Images smaller than 4 KB have a problem, and Twitter will complain 93 if os.path.getsize(res) < 4096: 94 os.remove(res) 95 return None 96 97 return res
252 def __download(self, data, resource): 253 self.i3s_client.golden_images.download(resource['uri'], data['destination_file_path']) 254 return True, self.MSG_DOWNLOADED, {}