Changeset - dd827e1dedde
[Not reviewed]
Dennis Fink - 9 years ago 2016-05-16 14:15:47
dennis.fink@c3l.lu
Fix IndexError
2 files changed with 7 insertions and 1 deletions:
0 comments (0 inline, 0 general)
ennstatus/api/model.py
Show inline comments
 
@@ -226,25 +226,28 @@ class Server:
 

	
 
        url = 'https://onionoo.torproject.org/weights?lookup={}'.format(
 
            self.fingerprint
 
        )
 

	
 
        data = requests.get(url)
 

	
 
        try:
 
            data.raise_for_status()
 
        except requests.HTTPError as e:
 
            raise e
 
        else:
 
            data = data.json()['relays'][0]
 
            try:
 
                data = data.json()['relays'][0]
 
            except IndexError as e:
 
                raise RuntimeError from e
 

	
 
        self.mean_consensus_weight = calculate_weight(data['consensus_weight'])
 
        self.mean_exit_probability = calculate_weight(data['exit_probability'])
 
        self.mean_guard_probability = calculate_weight(
 
            data['guard_probability']
 
        )
 
        self.mean_middle_probability = calculate_weight(
 
            data['middle_probability']
 
        )
 
        self.mean_consensus_weight_fraction = calculate_weight(
 
            data['consensus_weight_fraction']
 
        )
ennstatus/api/views.py
Show inline comments
 
@@ -114,24 +114,27 @@ def update():
 
        server = Server.from_dict(data)
 
    except Exception as e:
 
        current_app.logger.warning(' '.join([str(e), str(data)]))
 
        return str(e), 409, {'Content-Type': 'text/plain'}
 

	
 
    try:
 
        server.update_weights()
 
    except NotImplementedError:
 
        pass
 
    except requests.HTTPError as e:
 
        current_app.logger.error(str(e), exc_info=True)
 
        pass
 
    except RuntimeError as e:
 
        current_app.logger.error(str(e), exc_info=True)
 
        pass
 

	
 
    try:
 
        server.save()
 
    except Exception as e:
 
        current_app.logger.error(str(e))
 
        return str(e), 500, {'Content-Type': 'text/plain'}
 

	
 
    current_app.logger.info('Return result')
 
    return (
 
        server.json(), 201,
 
        {
 
            'Location': '/api/export/json/single?server_name={}'.format(
0 comments (0 inline, 0 general)