kopia lustrzana https://github.com/OpenDroneMap/WebODM
				
				
				
			Added timeout to api_client.py
							rodzic
							
								
									8939ba9b00
								
							
						
					
					
						commit
						fa843be5fc
					
				| 
						 | 
				
			
			@ -8,6 +8,7 @@ import json
 | 
			
		|||
import os
 | 
			
		||||
from urllib.parse import urlunparse
 | 
			
		||||
 | 
			
		||||
TIMEOUT = 10
 | 
			
		||||
 | 
			
		||||
class ApiClient:
 | 
			
		||||
    def __init__(self, host, port):
 | 
			
		||||
| 
						 | 
				
			
			@ -21,28 +22,28 @@ class ApiClient:
 | 
			
		|||
        return urlunparse(('http', netloc, url, '', '', ''))
 | 
			
		||||
 | 
			
		||||
    def info(self):
 | 
			
		||||
        return requests.get(self.url('/info')).json()
 | 
			
		||||
        return requests.get(self.url('/info'), timeout=TIMEOUT).json()
 | 
			
		||||
 | 
			
		||||
    def options(self):
 | 
			
		||||
        return requests.get(self.url('/options')).json()
 | 
			
		||||
        return requests.get(self.url('/options'), timeout=TIMEOUT).json()
 | 
			
		||||
 | 
			
		||||
    def task_info(self, uuid):
 | 
			
		||||
        return requests.get(self.url('/task/{}/info').format(uuid)).json()
 | 
			
		||||
        return requests.get(self.url('/task/{}/info').format(uuid), timeout=TIMEOUT).json()
 | 
			
		||||
 | 
			
		||||
    def task_output(self, uuid, line = 0):
 | 
			
		||||
        return requests.get(self.url('/task/{}/output?line={}').format(uuid, line)).json()
 | 
			
		||||
        return requests.get(self.url('/task/{}/output?line={}').format(uuid, line), timeout=TIMEOUT).json()
 | 
			
		||||
 | 
			
		||||
    def task_cancel(self, uuid):
 | 
			
		||||
        return requests.post(self.url('/task/cancel'), data={'uuid': uuid}).json()
 | 
			
		||||
        return requests.post(self.url('/task/cancel'), data={'uuid': uuid}, timeout=TIMEOUT).json()
 | 
			
		||||
 | 
			
		||||
    def task_remove(self, uuid):
 | 
			
		||||
        return requests.post(self.url('/task/remove'), data={'uuid': uuid}).json()
 | 
			
		||||
        return requests.post(self.url('/task/remove'), data={'uuid': uuid}, timeout=TIMEOUT).json()
 | 
			
		||||
 | 
			
		||||
    def task_restart(self, uuid):
 | 
			
		||||
        return requests.post(self.url('/task/restart'), data={'uuid': uuid}).json()
 | 
			
		||||
        return requests.post(self.url('/task/restart'), data={'uuid': uuid}, timeout=TIMEOUT).json()
 | 
			
		||||
 | 
			
		||||
    def task_download(self, uuid, asset):
 | 
			
		||||
        res = requests.get(self.url('/task/{}/download/{}').format(uuid, asset), stream=True)
 | 
			
		||||
        res = requests.get(self.url('/task/{}/download/{}').format(uuid, asset), stream=True, timeout=TIMEOUT)
 | 
			
		||||
        if "Content-Type" in res.headers and "application/json" in res.headers['Content-Type']:
 | 
			
		||||
            return res.json()
 | 
			
		||||
        else:
 | 
			
		||||
| 
						 | 
				
			
			@ -61,4 +62,5 @@ class ApiClient:
 | 
			
		|||
                 ) for image in images]
 | 
			
		||||
        return requests.post(self.url("/task/new"),
 | 
			
		||||
                             files=files,
 | 
			
		||||
                             data={'name': name, 'options': json.dumps(options)}).json()
 | 
			
		||||
                             data={'name': name, 'options': json.dumps(options)},
 | 
			
		||||
                             timeout=TIMEOUT).json()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue