I am trying to use an API that downloads a compressed folder containing different images. How can I use this Request url in Python to download the folder and choose the path in which I would like this folder to register ?
Request url :
I tried this :
import urllib.request
url = 'https://monitoring.greisch.com/api/dashboard/zipDashboard/298d5df9-4754-4f70-a228-e24a1bf6ac77/2019-08-18/2019-09-17/hour'
path ='R:/my/path/'
urllib.request.urlretrieve(url, path + 'Dashboard.zip')
print('file downloaded')
But I get this error message :
raceback (most recent call last):
File "C:\Program Files\Python\lib\urllib\request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "C:\Program Files\Python\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Program Files\Python\lib\http\client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Program Files\Python\lib\http\client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Program Files\Python\lib\http\client.py", line 1016, in _send_output
self.send(msg)
File "C:\Program Files\Python\lib\http\client.py", line 956, in send
self.connect()
File "C:\Program Files\Python\lib\http\client.py", line 1384, in connect
super().connect()
File "C:\Program Files\Python\lib\http\client.py", line 928, in connect
(self.host,self.port), self.timeout, self.source_address)
File "C:\Program Files\Python\lib\socket.py", line 727, in create_connection
raise err
File "C:\Program Files\Python\lib\socket.py", line 716, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée
But if I access the URL via a web browser, it works and the download of the compressed folder is automatically launched.
EDIT :
The solution was :
url = 'http://url.com/apirequest/'
wget.download(url, '/path/to/destination/folder/' + filename)