def __init__(self, http_session, is_secure, url, engineIO_session=None): super(WebsocketTransport, self).__init__( http_session, is_secure, url, engineIO_session) params = dict(http_session.params, **{ 'EIO': ENGINEIO_PROTOCOL, 'transport': 'websocket'}) request = http_session.prepare_request(requests.Request('GET', url)) kw = {'header': ['%s: %s' % x for x in request.headers.items()]} if engineIO_session: params['sid'] = engineIO_session.id kw['timeout'] = self._timeout = engineIO_session.ping_timeout ws_url = '%s://%s/?%s' % ( 'wss' if is_secure else 'ws', url, format_query(params)) http_scheme = 'https' if is_secure else 'http' if http_scheme in http_session.proxies: # Use the correct proxy proxy_url_pack = parse_url(http_session.proxies[http_scheme]) kw['http_proxy_host'] = proxy_url_pack.hostname kw['http_proxy_port'] = proxy_url_pack.port if proxy_url_pack.username: kw['http_proxy_auth'] = ( proxy_url_pack.username, proxy_url_pack.password) if http_session.verify: if http_session.cert: # Specify certificate path on disk if isinstance(http_session.cert, six.string_types): kw['ca_certs'] = http_session.cert else: kw['ca_certs'] = http_session.cert[0] else: # Do not verify the SSL certificate kw['sslopt'] = {'cert_reqs': ssl.CERT_NONE} try: self._connection = create_connection(ws_url, **kw) except Exception as e: raise ConnectionError(e)
def __init__(self, http_session, is_secure, url, engineIO_session=None): super(WebsocketTransport, self).__init__(http_session, is_secure, url, engineIO_session) params = dict(http_session.params, **{ 'EIO': ENGINEIO_PROTOCOL, 'transport': 'websocket' }) request = http_session.prepare_request(requests.Request('GET', url)) kw = {'header': ['%s: %s' % x for x in request.headers.items()]} if engineIO_session: params['sid'] = engineIO_session.id kw['timeout'] = self._timeout = engineIO_session.ping_timeout ws_url = '%s://%s/?%s' % ('wss' if is_secure else 'ws', url, format_query(params)) http_scheme = 'https' if is_secure else 'http' if http_scheme in http_session.proxies: # Use the correct proxy proxy_url_pack = parse_url(http_session.proxies[http_scheme]) kw['http_proxy_host'] = proxy_url_pack.hostname kw['http_proxy_port'] = proxy_url_pack.port if proxy_url_pack.username: kw['http_proxy_auth'] = (proxy_url_pack.username, proxy_url_pack.password) if http_session.verify: if http_session.cert: # Specify certificate path on disk if isinstance(http_session.cert, six.string_types): kw['ca_certs'] = http_session.cert else: kw['ca_certs'] = http_session.cert[0] else: # Do not verify the SSL certificate kw['sslopt'] = {'cert_reqs': ssl.CERT_NONE} try: self._connection = create_connection(ws_url, **kw) except Exception as e: raise ConnectionError(e)
def schedule_curl_callback(minute_count, base_url, value_by_key=None, headers=None, method='GET', with_retry=True): # Prepare more_lines full_url = base_url more_lines = [] if value_by_key: if method == 'POST': headers['Content-Type'] = 'application/json' more_lines.append('-d \'%s\'' % json.dumps(value_by_key)) else: full_url += format_query(value_by_key) if with_retry: more_lines.extend(['--retry 7']) more_lines.extend(['-X %s' % method, full_url]) # Prepare header_lines header_lines = [] for k, v in (headers or {}).items(): header_lines.append('-H "%s: %s"' % (k, v)) # Schedule callback shell_parts = ['curl'] + header_lines + more_lines shell_text = ' '.join(shell_parts) return schedule_shell_callback(minute_count, shell_text)
def schedule_curl_callback( minute_count, base_url, value_by_key=None, headers=None, method='GET', with_retry=True): # Prepare more_lines full_url = base_url more_lines = [] if value_by_key: if method == 'POST': headers['Content-Type'] = 'application/json' more_lines.append('-d \'%s\'' % json.dumps(value_by_key)) else: full_url += format_query(value_by_key) if with_retry: more_lines.extend(['--retry 7']) more_lines.extend(['-X %s' % method, full_url]) # Prepare header_lines header_lines = [] for k, v in (headers or {}).items(): header_lines.append('-H "%s: %s"' % (k, v)) # Schedule callback shell_parts = ['curl'] + header_lines + more_lines shell_text = ' '.join(shell_parts) return schedule_shell_callback(minute_count, shell_text)