Skip to content

Commit

Permalink
fix github TLS error
Browse files Browse the repository at this point in the history
  • Loading branch information
kmarkley committed Feb 23, 2018
1 parent 6245613 commit 89bcbe2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Mac Apps.indigoPlugin/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>PluginVersion</key>
<string>0.0.6</string>
<string>0.0.7</string>
<key>ServerApiVersion</key>
<string>2.0</string>
<key>IwsApiVersion</key>
Expand Down
32 changes: 17 additions & 15 deletions Mac Apps.indigoPlugin/Contents/Server Plugin/ghpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,29 @@ def getRateLimit(self):
# form a GET request to api.github.com and return the parsed JSON response
def _GET(self, requestPath):
self._debug('GET %s' % requestPath)

headers = {
'User-Agent': 'Indigo-Plugin-Updater',
'Accept': 'application/vnd.github.v3+json'
}

}
data = None

conn = httplib.HTTPSConnection('api.github.com')
conn.request('GET', requestPath, None, headers)

resp = conn.getresponse()
self._debug('HTTP %d %s' % (resp.status, resp.reason))

if (resp.status == 200):
data = json.loads(resp.read())
elif (400 <= resp.status < 500):
error = json.loads(resp.read())
requestPath = 'https://api.github.com'+ requestPath
#conn = httplib.HTTPSConnection('api.github.com')
#conn.request('GET', requestPath, None, headers)
#resp = conn.getresponse()
f = subprocess.Popen(["curl", requestPath], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
#'-H', str(headers), "-k",
out, err = f.communicate()
self._debug(u'HTTP Err result:'+unicode(err) )
self._debug(u'ReturnCode:{0}'.format(unicode(f.returncode)))
#self.sleep(1)
if (int(f.returncode) == 0):
data = json.loads(out)
self._debug(u'Json results:'+unicode(data))
elif (400 <= f.status < 500):
error = json.loads(out)
self._error('%s' % error['message'])
else:
self._error('Error: %s' % resp.reason)
self._error('Error: %s' % unicode(err))

return data

Expand Down
14 changes: 11 additions & 3 deletions Mac Apps.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def runConcurrentThread(self):

if loopStart > self.nextCheck:
self.checkForUpdates()
self.nextCheck = loopStart + k_updateCheckHours*60*60

self.sleep( loopStart + self.stateLoopFreq - time.time() )
except self.StopThread:
Expand Down Expand Up @@ -248,7 +247,16 @@ def actionControlDimmerRelay(self, action, dev):
# Menu Methods
#-------------------------------------------------------------------------------
def checkForUpdates(self):
self.updater.checkForUpdate()
try:
self.updater.checkForUpdate()
except Exception as e:
msg = 'Check for update error. Next attempt in {} hours.'.format(k_updateCheckHours)
if self.debug:
self.logger.exception(msg)
else:
self.logger.error(msg)
self.logger.debug(e)
self.nextCheck = time.time() + k_updateCheckHours*60*60

#-------------------------------------------------------------------------------
def updatePlugin(self):
Expand Down Expand Up @@ -295,7 +303,7 @@ def update(self, doStats=False):
self.states['onOffState'] = bool(self.psInfo)

if doStats or (self.onState != self.dev.onState):
if self.onState and self.psInfo:
if self.onState:
stats = re_extract(self.psInfo, k_psInfoGroupsRegex, k_psInfoGroupsKeys)
self.status = stats['state']
self.states['process_id'] = stats['pid']
Expand Down

0 comments on commit 89bcbe2

Please sign in to comment.