[heartbeat] python2: remove explicit http method

pull/86/head
insaneracist 4 years ago
parent 89ada4406a
commit 12ab8cf6c5

@ -263,7 +263,6 @@ class NiconicoIE(InfoExtractor):
'data': json.dumps(session_response['data']), 'data': json.dumps(session_response['data']),
'headers': heartbeat_headers, 'headers': heartbeat_headers,
'interval': session_api_data['heartbeat_lifetime'] / 2000, 'interval': session_api_data['heartbeat_lifetime'] / 2000,
'method': 'POST',
'url': heartbeat_url, 'url': heartbeat_url,
} }

@ -18,11 +18,12 @@ class Heartbeat(object):
data = params.get('data') data = params.get('data')
if isinstance(data, compat_str): if isinstance(data, compat_str):
data = data.encode() data = data.encode()
# Python 2 does not allow us to set HTTP method
# it is POST if Request has data, otherwise GET
self.request = sanitized_Request( self.request = sanitized_Request(
params.get('url'), params.get('url'),
data=data, data=data,
headers=params.get('headers', {}), headers=params.get('headers', {})
method=params.get('method')
) )
self.interval = params.get('interval', 30) self.interval = params.get('interval', 30)
@ -49,7 +50,7 @@ class Heartbeat(object):
self.ydl.to_screen('[heartbeat]') self.ydl.to_screen('[heartbeat]')
self.ydl.urlopen(self.request) self.ydl.urlopen(self.request)
except Exception: except Exception:
self.ydl.report_warning("[heartbeat] Heartbeat failed") self.ydl.report_warning("Heartbeat failed")
if self.ydl.params.get('verbose'): if self.ydl.params.get('verbose'):
self.ydl.to_stderr(encode_compat_str(traceback.format_exc())) self.ydl.to_stderr(encode_compat_str(traceback.format_exc()))
self.parent_thread.join(self.interval) self.parent_thread.join(self.interval)

Loading…
Cancel
Save