From 440bc00284b25aa3d7203ed078121b2e914dc04a Mon Sep 17 00:00:00 2001 From: Ryan Bagwell Date: Wed, 28 Jan 2015 10:30:44 -0600 Subject: [PATCH] Adding optional timeout for urlopen --- pywmata.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pywmata.py b/pywmata.py index d20fb8f..36fe5e9 100644 --- a/pywmata.py +++ b/pywmata.py @@ -16,8 +16,9 @@ class Wmata(object): base_url = 'http://api.wmata.com/%(svc)s.svc/json/%(endpoint)s' - def __init__(self, apikey): + def __init__(self, apikey, timeout=30): self.apikey = apikey + self.timeout = timeout def _build_url(self, svc, endpoint, query={}): query.update({'api_key': self.apikey}) @@ -27,7 +28,7 @@ def _build_url(self, svc, endpoint, query={}): def _get(self, svc, endpoint, query={}): self.url = self._build_url(svc, endpoint, query) - response = urlopen(self.url) + response = urlopen(self.url, None, self.timeout) if response.msg == 'OK': self.data = json.loads(response.read())