def __init__(self, con_pool_size=1, proxy_url=None, urllib3_proxy_kwargs=None): try: if urllib3_proxy_kwargs is None: urllib3_proxy_kwargs = dict() # This was performed on Windows only, but it shouldn't be a problem # managing cacert.pem on Linux as well #if os.name == 'nt': try: import urllib2 import tempfile capath = os.path.join(tempfile.gettempdir(), 'tg-cacert.pem') # Check if tg-cacert.pem exists and if it's older than 7 days if not os.path.exists(capath) or (os.path.exists(capath) \ and (time.time() - os.path.getctime(capath)) // (24 * 3600) >= 7): CACERT_URL = "https://curl.haxx.se/ca/cacert.pem" request = urllib2.Request(CACERT_URL) file_contents = urllib2.urlopen(request).read() log.debug("## Telegramer downloaded "+os.path.realpath(capath)) cafile = open(os.path.realpath(capath), 'wb') cafile.write(file_contents) cafile.close() except: try: capath = certifi.where() except: capath = os.path.join(tempfile.gettempdir(), 'tg-cacert.pem') kwargs = dict( maxsize=con_pool_size, cert_reqs='CERT_REQUIRED', ca_certs=capath, #ca_certs=certifi.where(), socket_options=HTTPConnection.default_socket_options + [ (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), ]) # Set a proxy according to the following order: # * proxy defined in proxy_url (+ urllib3_proxy_kwargs) # * proxy set in `HTTPS_PROXY` env. var. # * proxy set in `https_proxy` env. var. # * None (if no proxy is configured) if not proxy_url: proxy_url = os.environ.get('HTTPS_PROXY') or os.environ.get('https_proxy') if not proxy_url: mgr = urllib3.PoolManager(**kwargs) else: kwargs.update(urllib3_proxy_kwargs) mgr = urllib3.proxy_from_url(proxy_url, **kwargs) if mgr.proxy.auth: # TODO: what about other auth types? auth_hdrs = urllib3.make_headers(proxy_basic_auth=mgr.proxy.auth) mgr.proxy_headers.update(auth_hdrs) self._con_pool = mgr except Exception as e: log.error(str(e) + '\n' + traceback.format_exc())
def _doPushToHCP(self,hcpDeviceId,messageTypeIdToDevice,payload,dummyMode=False): try: urllib3.disable_warnings() except: print("urllib3.disable_warnings() failed - get a recent enough urllib3 version to avoid potential InsecureRequestWarning warnings! Will continue though.") # use with or without proxy if (config.proxy_url == ''): http = urllib3.PoolManager() else: http = urllib3.proxy_from_url(config.proxy_url) push_url='https://iotmms' + config.hcp_account_id + config.hcp_landscape_host + '/com.sap.iotservices.mms/v1/api/http/push/' + str(hcpDeviceId) self.info('push url:\n ' + push_url) # use with authentication headers = urllib3.util.make_headers(user_agent=None) headers['Authorization'] = config.hcp_authorization_header headers['Content-Type'] = 'application/json;charset=utf-8' bodyObj = { 'method' : self.method, 'sender' : self.name, 'messageType' : messageTypeIdToDevice, 'messages' : [payload] } body = json.dumps(bodyObj) self.info('message body:\n ' + body) if dummyMode: #self.info("Dummy mode is active, not pushing anything to HCP.") return try: r = http.urlopen('POST', push_url, body=body, headers=headers) self.info('push_to_hcp(): ' + str(r.status) + ' ' + r.data) except Exception as e: self.info(str(e))
def send_to_hcp(self,message): device = self.device debug_communication = 1 #self.info("to hcp: " + message) if (config.proxy_url == ''): http = urllib3.PoolManager() else: http = urllib3.proxy_from_url(config.proxy_url) url='https://iotmms' + config.hcp_account_id + config.hcp_landscape_host + '/com.sap.iotservices.mms/v1/api/http/data/' + str(device.hcpDeviceId) if debug_communication == 1: self.info('url: ' + url) headers = urllib3.util.make_headers(user_agent=None) # use with authentication headers['Authorization'] = 'Bearer ' + device.hcpOauthCredentials headers['Content-Type'] = 'application/json;charset=utf-8' # construct the body body = '{ "mode" : "async", "messageType" : "' + str(device.messageTypeId) + '", "messages" : ' body += message body += '}' if debug_communication == 1: print body else: self.info("[" + self.idstr + "] message to hcp: " + (' '.join(message.split('\n')))) r = http.urlopen('POST', url, body=body, headers=headers) if debug_communication == 1: self.info("send_to_hcp():" + str(r.status)) self.info(r.data) else: self.info("[" + self.idstr + "] response status: " + str(r.status) + " " + r.data)
def __init__(self, con_pool_size=1, proxy_url=None, urllib3_proxy_kwargs=None): if urllib3_proxy_kwargs is None: urllib3_proxy_kwargs = dict() kwargs = dict( maxsize=con_pool_size, cert_reqs='CERT_REQUIRED', ca_certs=certifi.where(), socket_options=HTTPConnection.default_socket_options + [ (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), ]) # Set a proxy according to the following order: # * proxy defined in proxy_url (+ urllib3_proxy_kwargs) # * proxy set in `HTTPS_PROXY` env. var. # * proxy set in `https_proxy` env. var. # * None (if no proxy is configured) if not proxy_url: proxy_url = os.environ.get('HTTPS_PROXY') or os.environ.get('https_proxy') if not proxy_url: mgr = urllib3.PoolManager(**kwargs) else: kwargs.update(urllib3_proxy_kwargs) mgr = urllib3.proxy_from_url(proxy_url, **kwargs) if mgr.proxy.auth: # TODO: what about other auth types? auth_hdrs = urllib3.make_headers(proxy_basic_auth=mgr.proxy.auth) mgr.proxy_headers.update(auth_hdrs) self._con_pool = mgr
def run(self): # disable InsecureRequestWarning if your are working without certificate verification # see https://urllib3.readthedocs.org/en/latest/security.html # be sure to use a recent enough urllib3 version if this fails try: urllib3.disable_warnings() except: print("__HANA__: urllib3.disable_warnings() failed - get a recent enough urllib3 version to avoid potential InsecureRequestWarning warnings! Can and will continue though.") # use with or without proxy if (config.proxy_url == ''): self.http = urllib3.PoolManager() else: self.http = urllib3.proxy_from_url(config.proxy_url) self.url='https://iotmms' + config.hcp_account_id + config.hcp_landscape_host + '/com.sap.iotservices.mms/v1/api/http/data/' + str(config.device_id) self.headers = urllib3.util.make_headers(user_agent=None) # use with authentication self.headers['Authorization'] = 'Bearer ' + config.oauth_credentials_for_device self.headers['Content-Type'] = 'application/json;charset=utf-8' print("__HANA__: Success at IoT Service Config") self.initialized = True while not self.stop: time.sleep(1) self.send_to_hcp(int(time.time()), "CC2650_01", self.sensor_data[3][0], self.sensor_data[3][1], self.sensor_data[3][2], self.sensor_data[6][0], self.sensor_data[5][0])
def create_code(submission): url = "http://codeforces.com/contest/" + str( submission['contestId']) + "/submission/" + str(submission['id']) if (flags['proxy'] == 1): http = urllib3.proxy_from_url(proxyDict['http']) else: http = urllib3.connection_from_url(url) handle = http.request('GET', url) html_gunk = handle.data #print(html_gunk) soup = BeautifulSoup(html_gunk, 'html.parser') #subprocess.call(["touch", './source-code/' + str(submission['id']) + ".cpp"]) fi3 = open('./source-code/' + str(submission['id']) + ".cpp", "w") fi3.write("//Language: " + str(submission['programmingLanguage']) + "\n\n\n") try: result = soup.pre.get_text().encode('utf-8', errors='replace').decode('utf-8') except AttributeError: result = bs4_error_text except UnicodeDecodeError: result = '<CHAR>' except UnicodeEncodeError: result = '<CHAR>' fi3.write(result) fi3.close()
def sendinfo(long): try: urllib3.disable_warnings() except: print( "urllib3.disable_warnings() failed - get a recent enough urllib3 version to avoid potential InsecureRequestWarning warnings! Can and will continue though." ) # use with or without proxy if (config.proxy_url == ''): http = urllib3.PoolManager() else: http = urllib3.proxy_from_url(config.proxy_url) url = 'https://iotmms' + config.hcp_account_id + config.hcp_landscape_host + '/com.sap.iotservices.mms/v1/api/http/data/' + str( config.device_id) # print("Host " + config.hcp_account_id + config.hcp_landscape_host) headers = urllib3.util.make_headers(user_agent=None) # use with authentication headers['Authorization'] = 'Bearer ' + config.oauth_credentials_for_device headers['Content-Type'] = 'application/json;charset=utf-8' send_to_hcp(http, url, headers, str(long)) #sendinfo("port", 1.22334343, 43.2343, 23.44, 9.33, 1.5, 0.95)
def main(): requests.packages.urllib3.disable_warnings(InsecureRequestWarning) http = urllib3.proxy_from_url('http://localhost:8080') r = http.request('GET', 'https://www.hackthis.co.uk/levels/coding/2', headers={'Content-Type': 'application/x-www-form-urlencoded', 'Referer': 'https://www.hackthis.co.uk/levels/coding/1', 'Cookie': '_ga=GA1.3.1869636339.1470506230; autologin=cI%13%923%B0U%CB%DA%84%7F%3D2%1E%ACn%89%C7%EA6Z%24%1C%19%24%951F1cj%EB%5D%D9%FD%85%15%D2a%C5H%9ED%BCe%DB%99%DE%1D%F2%EE%FA%C6%9A%F6%18%93%1E%C1%C33%22%92%14; member=1; PHPSESSID=kdqce5kp5fg5nnmcjlt9jfuii7; _gat=1' }) html = r.data.decode('utf-8') soup = BeautifulSoup.BeautifulSoup(html) textarea = soup.findAll('textarea')[0] text = textarea.contents[0] elements = text.split(',') for element in elements: try: print str(unichr(int(element)+32)) except: print "" output = ", ".join(sorted(elements)) #addToClipBoard(output) """
def ProxyRequestPage(url,host,port): try: proxy = urllib3.proxy_from_url('http://'+host+':'+port+'/',timeout=20.0) html = proxy.request('GET', url) except: html='' return html
def __init__(self, con_pool_size=1, proxy_url=None, urllib3_proxy_kwargs=None): if urllib3_proxy_kwargs is None: urllib3_proxy_kwargs = dict() kwargs = dict( maxsize=con_pool_size, cert_reqs="CERT_REQUIRED", ca_certs=certifi.where(), socket_options=HTTPConnection.default_socket_options + [(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)], ) # Set a proxy according to the following order: # * proxy defined in proxy_url (+ urllib3_proxy_kwargs) # * proxy set in `HTTPS_PROXY` env. var. # * proxy set in `https_proxy` env. var. # * None (if no proxy is configured) if not proxy_url: proxy_url = os.environ.get("HTTPS_PROXY") or os.environ.get("https_proxy") if not proxy_url: mgr = urllib3.PoolManager(**kwargs) else: kwargs.update(urllib3_proxy_kwargs) mgr = urllib3.proxy_from_url(proxy_url, **kwargs) if mgr.proxy.auth: # TODO: what about other auth types? auth_hdrs = urllib3.make_headers(proxy_basic_auth=mgr.proxy.auth) mgr.proxy_headers.update(auth_hdrs) self._con_pool = mgr
def ProxyRequestPage(url, host, port): try: proxy = urllib3.proxy_from_url('http://' + host + ':' + port + '/', timeout=20.0) html = proxy.request('GET', url) except: html = '' return html
def download(url, method="GET", params={}, body=None, headers={}, proxys=[]): if not url: raise DownloadException("Url is None") if isinstance(url, unicode): url = url.encode('utf8') for k, v in params.iteritems(): if isinstance(v, unicode): params[k] = v.encode('utf8') if params: if method == "GET" and url.find('?') == -1: url = url + "?" + urllib.urlencode(params) elif method == "POST": body = urllib.urlencode(params) parse = urlparse.urlparse(url) site = parse.netloc if _SITES_RATE_LIMIT.has_key(site): global _SITES_LAST_ACCESS last_visit = _SITES_LAST_ACCESS.get(site) now = unix_time() if last_visit: waittime = last_visit + _SITES_RATE_LIMIT[site] - now if waittime > 0: time.sleep(waittime) _SITES_LAST_ACCESS[site] = now proxy = proxys[random.randint(0, len(proxys) - 1)] if proxys else None pool = _HTTP if proxy: if not _PROXY.has_key(proxy): _PROXY[proxy] = urllib3.proxy_from_url(proxy) pool = _PROXY[proxy] _headers = _DEFAULT_HEADER _headers["Host"] = parse.netloc for k, v in headers.iteritems(): if not v and _headers.has_key(k): _headers.pop(k) else: _headers[k] = v resp = pool.urlopen(method=method, url=url, body=body, headers=_headers) resp = process_response(resp) if resp.status in [301, 302]: redirect_url = resp.headers.get('location') resp = download(url=redirect_url, method=method, params=params, body=body, headers=headers, proxy=proxy) elif resp.status >= 400: raise DownloadException(status=resp.status) return resp
def _get_proxy_manager(self, proxy_url): if proxy_url not in self._proxy_managers: proxy_headers = self._proxy_config.proxy_headers_for(proxy_url) proxy_manager_kwargs = self._get_pool_manager_kwargs( proxy_headers=proxy_headers) proxy_manager = proxy_from_url(proxy_url, **proxy_manager_kwargs) proxy_manager.pool_classes_by_scheme = self._pool_classes_by_scheme self._proxy_managers[proxy_url] = proxy_manager return self._proxy_managers[proxy_url]
def __init__(self, con_pool_size=1, proxy_url=None, urllib3_proxy_kwargs=None, connect_timeout=5., read_timeout=5.): if urllib3_proxy_kwargs is None: urllib3_proxy_kwargs = dict() self._connect_timeout = connect_timeout kwargs = dict(maxsize=con_pool_size, cert_reqs='CERT_REQUIRED', ca_certs=certifi.where(), socket_options=HTTPConnection.default_socket_options + [ (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), ], timeout=urllib3.Timeout(connect=self._connect_timeout, read=read_timeout, total=None)) # Set a proxy according to the following order: # * proxy defined in proxy_url (+ urllib3_proxy_kwargs) # * proxy set in `HTTPS_PROXY` env. var. # * proxy set in `https_proxy` env. var. # * None (if no proxy is configured) if not proxy_url: proxy_url = os.environ.get('HTTPS_PROXY') or os.environ.get( 'https_proxy') if not proxy_url: if urllib3.contrib.appengine.is_appengine_sandbox(): # Use URLFetch service if running in App Engine mgr = urllib3.contrib.appengine.AppEngineManager() else: mgr = urllib3.PoolManager(**kwargs) else: kwargs.update(urllib3_proxy_kwargs) if proxy_url.startswith('socks'): try: from urllib3.contrib.socks import SOCKSProxyManager except ImportError: raise RuntimeError('PySocks is missing') mgr = SOCKSProxyManager(proxy_url, **kwargs) else: mgr = urllib3.proxy_from_url(proxy_url, **kwargs) if mgr.proxy.auth: # TODO: what about other auth types? auth_hdrs = urllib3.make_headers( proxy_basic_auth=mgr.proxy.auth) mgr.proxy_headers.update(auth_hdrs) self._con_pool = mgr
def sendMsg(self, json_msg): aJson = json.loads(json_msg) sAccount = aJson[u'args'][0][u'account'] sDevice = aJson[u'args'][0][u'device'] sToken = aJson[u'args'][0][u'devToken'] sMsgType = aJson[u'args'][0][u'messType'] sProxy = aJson[u'args'][0][u'proxy'] aMessages = aJson[u'args'][0][u'messages'][0] jMessages = json.dumps(aMessages) # use with or without proxy http = urllib3.PoolManager( cert_reqs='CERT_REQUIRED', # Force certificate check. ca_certs=certifi.where(), # Path to the Certifi bundle. ) # set the proxy when applicable if sProxy != '': http = urllib3.proxy_from_url(sProxy) print('-------------------- \n') # URL preparation url = 'https://iotmms' + sAccount + '.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/data/' + sDevice print('URL : ' + url) print('\n') # HEADERS preparation aHeader = urllib3.util.make_headers() # use with authentication aHeader['Authorization'] = 'Bearer ' + sToken aHeader['Content-Type'] = 'application/json;charset=utf-8' # BODY preparation aBody_mode = '"mode":"async"' aBody_msgType = '"messageType":"' + sMsgType + '"' aBody_messages = '"messages" : [' + jMessages + ']' aBody = '{' + aBody_mode + ', ' + aBody_msgType + ', ' + aBody_messages + '}' print('Body : ' + aBody) print('\n') print('-------------------- \n') try: r = http.urlopen('POST', url, body=aBody, headers=aHeader) print('\n') print('[Status return] ' + str(r.status)) print('[Return msg ] ' + str(r.data)) except urllib3.exceptions.SSLError as e: print(e)
def _poll_from_hcp(self,processFun=None): device = self debug_communication = 1 #self.info("to hcp: " + message) if (config.proxy_url == ''): http = urllib3.PoolManager() else: http = urllib3.proxy_from_url(config.proxy_url) url='https://iotmms' + config.hcp_account_id + config.hcp_landscape_host + '/com.sap.iotservices.mms/v1/api/http/data/' + str(device.hcpDeviceId) # https://iotmmsi806258trial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/data/ if debug_communication == 1: self.info('url: ' + url) headers = urllib3.util.make_headers(user_agent=None) # use with authentication headers['Authorization'] = 'Bearer ' + device.hcpOauthCredentials #headers['Authorization'] = config.hcp_authorization_header headers['Content-Type'] = 'application/json;charset=utf-8' if processFun == None: processFun = lambda payload: self.info(str(payload)) isfun = hasattr(processFun,'__call__') try: r = http.urlopen('GET', url, headers=headers) self.info("poll_from_hcp():" + str(r.status)) if (debug_communication == 1): self.info(r.data) json_string='{"all_messages":'+(r.data).decode("utf-8")+'}' try: json_string_parsed=json.loads(json_string) # print(json_string_parsed) # take care: if multiple messages arrive in 1 payload - their order is last in / first out - so we need to traverse in reverese order try: messages_reversed=reversed(json_string_parsed["all_messages"]) for single_message in messages_reversed: # print(single_message) payload=single_message["messages"][0] if isfun: processFun(payload) except TypeError as te: if debug_communication: self.info("Problem decoding the message " + (r.data).decode("utf-8") + ": " + str(te)) except ValueError as ve: if debug_communication: self.info("Problem decoding the message " + (r.data).decode("utf-8") + ": " + str(ve)) except Exception as e001: self.info(str(e001))
def __init__(self, api_key: str, proxy: str = None): """ Initializes ParseHub objects :param api_key: your API key from either PH website or browser plugin :param proxy: if needed, in format http[s]://host:port """ self.api_key = api_key if proxy: self.conn = urllib3.proxy_from_url(proxy) else: self.conn = urllib3.PoolManager() self.projects = [project for project in self.getprojects()]
def __init__(self, api_key, proxy=None): u""" Initializes ParseHub objects :param api_key: your API key from either PH website or browser plugin :param proxy: if needed, in format http[s]://host:port """ self.api_key = api_key if proxy: self.conn = urllib3.proxy_from_url(proxy) else: self.conn = urllib3.PoolManager() self.projects = [project for project in self.getprojects()]
def clicked(): mdp = txtMDP.get() identifiant = txtId.get() proxies = {'http': 'http://172.30.137.29:3128'} print("Using HTTP proxy %s" % proxies['http']) http = urllib3.proxy_from_url('http://172.30.137.29:3128') response = http.request( "GET", "http://www.btssio-carcouet.fr/ppe4/public/connect2/" + identifiant + "/" + mdp + "/infirmiere") soup = BeautifulSoup(response.data) print(soup) data = json.loads(str(soup.text)) print(data) checkStatus(data, identifiant)
def __init__(self, pools_size=4, config=configuration): # urllib3.PoolManager will pass all kw parameters to connectionpool # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # ca_certs vs cert_file vs key_file # http://stackoverflow.com/a/23957365/2985775 # cert_reqs if config.verify_ssl: cert_reqs = ssl.CERT_REQUIRED else: cert_reqs = ssl.CERT_NONE # ca_certs if config.ssl_ca_cert: ca_certs = config.ssl_ca_cert else: # if not set certificate file, use Mozilla's root certificates. ca_certs = certifi.where() # cert_file cert_file = config.cert_file # key file key_file = config.key_file kwargs = { 'num_pools': pools_size, 'cert_reqs': cert_reqs, 'ca_certs': ca_certs, 'cert_file': cert_file, 'key_file': key_file, } if config.connection_pool_maxsize is not None: kwargs['maxsize'] = config.connection_pool_maxsize if config.assert_hostname is not None: kwargs['assert_hostname'] = config.assert_hostname # https pool manager if config.http_proxy_url is not None: self.pool_manager = urllib3.proxy_from_url( config.http_proxy_url, **kwargs ) else: self.pool_manager = urllib3.PoolManager( **kwargs )
def _get_proxy_manager(self, proxy_url): if proxy_url not in self._proxy_managers: proxy_headers = self._proxy_config.proxy_headers_for(proxy_url) proxy_manager = proxy_from_url( proxy_url, strict=True, timeout=self._timeout, proxy_headers=proxy_headers, maxsize=self._max_pool_connections, ssl_context=self._get_ssl_context(), ) proxy_manager.pool_classes_by_scheme = self._pool_classes_by_scheme self._proxy_managers[proxy_url] = proxy_manager return self._proxy_managers[proxy_url]
def main(): argparser = argparse.ArgumentParser() argparser.add_argument('client_language', help='Client language to setup spec for') argparser.add_argument( 'kubernetes_branch', help='Branch/tag of github.com/kubernetes/kubernetes to get spec from') argparser.add_argument('output_spec_path', help='Path to output spec file to') argparser.add_argument('username', help='Optional username if working on forks', default='kubernetes') argparser.add_argument( 'repository', help= 'Optional repository name if working with kubernetes ecosystem projects', default='kubernetes') args = argparser.parse_args() unprocessed_spec = args.output_spec_path + ".unprocessed" in_spec = "" if os.environ.get("OPENAPI_SKIP_FETCH_SPEC") or False: with open(unprocessed_spec, 'r') as content: in_spec = json.load(content, object_pairs_hook=OrderedDict) else: proxy = os.getenv('HTTP_PROXY') if proxy: pool = urllib3.proxy_from_url(proxy) else: pool = urllib3.PoolManager() spec_url = 'https://raw.githubusercontent.com/%s/%s/' \ '%s/api/openapi-spec/swagger.json' % (args.username, args.repository, args.kubernetes_branch) with pool.request('GET', spec_url, preload_content=False) as response: if response.status != 200: print("Error downloading spec file %s. Reason: %s" % (spec_url, response.reason)) return 1 in_spec = json.load(response, object_pairs_hook=OrderedDict) write_json(unprocessed_spec, in_spec) # use version from branch/tag name if spec doesn't provide it if in_spec['info']['version'] == 'unversioned': in_spec['info']['version'] = args.kubernetes_branch crd_mode = os.environ.get('KUBERNETES_CRD_MODE') or False out_spec = process_swagger(in_spec, args.client_language, crd_mode) write_json(args.output_spec_path, out_spec) return 0
def request(self, url): """Request handler""" if True == self.proxy: proxyserver = self.reader.get_random_proxy() try: conn = urllib3.proxy_from_url(proxyserver, maxsize=10, block=True, timeout=self.rest) except urllib3.exceptions.ProxySchemeUnknown as e: Log.critical('{} : {}'.format(e.message, proxyserver)) else: try: conn = urllib3.connection_from_url(url, maxsize=10, block=True, timeout=self.rest) except TypeError as e: Log.critical(e.message) headers = { 'accept-encoding': 'gzip, deflate, sdch', 'accept-language': 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4,uk;q=0.2,es;q=0.2', 'cache-control': 'no-cache', 'user-agent': self.reader.get_random_user_agent() } try: response = conn.request(config.DEFAULT_HTTP_METHOD, url, headers=headers, redirect=False) except (urllib3.exceptions.ConnectTimeoutError, urllib3.exceptions.HostChangedError, urllib3.exceptions.ReadTimeoutError, urllib3.exceptions.ProxyError, ) as e: response = None self.iterator = Progress.line(url + ' -> ' + e.message, self.urls.__len__(), 'warning', self.iterator) except urllib3.exceptions.MaxRetryError: pass except urllib3.exceptions.NewConnectionError as e: Log.critical(e.message) except exceptions.AttributeError as e: Log.critical(e.message) except TypeError as e: Log.critical(e.message) try: time.sleep(self.delay) return self.response(response, url) except exceptions.UnboundLocalError: Log.warning(self.message.get('unresponsible').format(url)) pass
def _init_con_pool(): global _CON_POOL kwargs = dict(maxsize=CON_POOL_SIZE, cert_reqs='CERT_REQUIRED', ca_certs=certifi.where(), socket_options=HTTPConnection.default_socket_options + [ (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), ]) proxy_url = _get_con_pool_proxy() if not proxy_url: mgr = urllib3.PoolManager(**kwargs) else: if _CON_POOL_PROXY_KWARGS: kwargs.update(_CON_POOL_PROXY_KWARGS) mgr = urllib3.proxy_from_url(proxy_url, **kwargs) if mgr.proxy.auth: # TODO: what about other auth types? auth_hdrs = urllib3.make_headers(proxy_basic_auth=mgr.proxy.auth) mgr.proxy_headers.update(auth_hdrs) _CON_POOL = mgr
def main(): argparser = argparse.ArgumentParser() argparser.add_argument('client_language', help='Client language to setup spec for') argparser.add_argument( 'kubernetes_branch', help='Branch of github.com/kubernetes/kubernetes to get spec from') argparser.add_argument('output_spec_path', help='Path to output spec file to') argparser.add_argument('username', help='Optional username if working on forks', default='kubernetes') argparser.add_argument( 'repository', help= 'Optional repository name if working with kubernetes ecosystem projects', default='kubernetes') args = argparser.parse_args() spec_url = 'https://raw.githubusercontent.com/%s/%s/' \ '%s/api/openapi-spec/swagger.json' % (args.username, args.repository, args.kubernetes_branch) proxy = os.getenv('HTTP_PROXY') if proxy: pool = urllib3.proxy_from_url(proxy) else: pool = urllib3.PoolManager() with pool.request('GET', spec_url, preload_content=False) as response: if response.status != 200: print("Error downloading spec file %s. Reason: %s" % (spec_url, response.reason)) return 1 in_spec = json.load(response, object_pairs_hook=OrderedDict) write_json(args.output_spec_path + ".unprocessed", in_spec) out_spec = process_swagger(in_spec, args.client_language) write_json(args.output_spec_path, out_spec) return 0
def create_code(submission): url = "http://codeforces.com/contest/" + str(submission['contestId']) + "/submission/" + str(submission['id']) if(flags['proxy']==1): http = urllib3.proxy_from_url(proxyDict['http']) else: http = urllib3.connection_from_url(url) handle = http.request('GET',url) html_gunk = handle.data #print(html_gunk) soup = BeautifulSoup(html_gunk, 'html.parser') #subprocess.call(["touch", './source-code/' + str(submission['id']) + ".cpp"]) fi3 = open('./source-code/' + str(submission['id']) + ".cpp" , "w") fi3.write("//Language: " + str(submission['programmingLanguage']) + "\n\n\n") try: result = soup.pre.get_text().encode('utf-8', errors='replace').decode('utf-8') except AttributeError: result = bs4_error_text except UnicodeDecodeError: result = '<CHAR>' except UnicodeEncodeError: result = '<CHAR>' fi3.write(result) fi3.close()
#!/usr/bin/env python import datetime import time import urllib3 # disable InsecureRequestWarning if your are working without certificate verification # see https://urllib3.readthedocs.org/en/latest/security.html # be sure to use a recent enough urllib3 version if this fails try: urllib3.disable_warnings() except: print('urllib3.disable_warnings() failed - get a recent enough urllib3 version to avoid potential InsecureRequestWarning warnings! Can and will continue though.') # use with or without proxy #http = urllib3.PoolManager() http = urllib3.proxy_from_url('http://proxy.pal.sap.corp:8080') # interaction for a specific Device instance - replace 1 with your specific Device ID #url = 'https://iotmms_on_your_trial_system.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/data/1' url = 'https://iotmmsi326045trial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/data/' deviceID = '5f2d9b1c-7979-4ab3-a012-2a809ca6b797' url = url +deviceID headers = urllib3.util.make_headers() # use with authentication # please insert correct OAuth token headers['Authorization'] = 'Bearer ' + 'd468433e2f2e4467266d32669456c44' headers['Content-Type'] = 'application/json;charset=utf-8' #I just started with random numbers, you can choose what ever you like temperature =29 humidity =5 #just put in 3 rows into the DB #for x in range(0, 3): while True: current_time = int (time.time())
f3.b2.pack(side=LEFT) root.mainloop() # === main starts here =============================================== # disable InsecureRequestWarning if your are working without certificate verification # see https://urllib3.readthedocs.org/en/latest/security.html # be sure to use a recent enough urllib3 version if this fails try: urllib3.disable_warnings() except: print( "urllib3.disable_warnings() failed - get a recent enough urllib3 version to avoid potential InsecureRequestWarning warnings! Can and will continue though." ) # use with or without proxy if (config.proxy_url == ''): http = urllib3.PoolManager() else: http = urllib3.proxy_from_url(config.proxy_url) push_url = 'https://iotmms' + config.hcp_account_id + config.hcp_landscape_host + '/com.sap.iotservices.mms/v1/api/http/push/' + str( config.device_id) # use with authentication headers = urllib3.util.make_headers(basic_auth=config.hcp_user_credentials) headers['Content-Type'] = 'text/plain;charset=utf-8' build_and_start_ui()
import urllib3 import uuid namespaces = { "csw": "http://www.opengis.net/cat/csw/2.0.2", "gmd": "http://www.isotc211.org/2005/gmd", "gco": "http://www.isotc211.org/2005/gco" } ET.register_namespace("csw", "http://www.opengis.net/cat/csw/2.0.2") ET.register_namespace("gmd", "http://www.isotc211.org/2005/gmd") ET.register_namespace("gco", "http://www.isotc211.org/2005/gco") urllib3.disable_warnings() http_proxy = os.environ.get('http_proxy') http = urllib3.proxy_from_url( http_proxy) if http_proxy else urllib3.PoolManager() def fetch_metadata_from_csw(catalogue): def get_request(): request_filename = catalogue[0] + "/request.xml" request_body = read_file(request_filename) return http.urlopen("POST", catalogue[1], headers={"Content-type": "text/xml"}, body=request_body) fetch_metadata(catalogue, get_request) def fetch_metadata_from_url(catalogue):
signal.signal(signal.SIGINT, signal_handler) # disable InsecureRequestWarning if your are working without certificate verification # see https://urllib3.readthedocs.org/en/latest/security.html # be sure to use a recent enough urllib3 version if this fails try: urllib3.disable_warnings() except: print("urllib3.disable_warnings() failed - get a recent enough urllib3 version to avoid potential InsecureRequestWarning warnings! Can and will continue though.") # use with or without proxy if (config.proxy_url == ''): http = urllib3.PoolManager() else: http = urllib3.proxy_from_url(config.proxy_url) url='https://iotmms' + config.hcp_account_id + config.hcp_landscape_host + '/com.sap.iotservices.mms/v1/api/http/data/' + str(config.device_id) headers = urllib3.util.make_headers(user_agent=None) # use with authentication headers['Authorization'] = 'Bearer ' + config.oauth_credentials_for_device headers['Content-Type'] = 'application/json;charset=utf-8' # initialize HW # Connect the Grove Slide Potentiometer to analog port A0 slider=0 # pin 1 (yellow wire) grovepi.pinMode(slider, "INPUT") # Connect the Grove LED to digital port D4
import urllib3 import uuid namespaces = { "csw": "http://www.opengis.net/cat/csw/2.0.2", "gmd": "http://www.isotc211.org/2005/gmd", "gco": "http://www.isotc211.org/2005/gco" } ET.register_namespace("csw", "http://www.opengis.net/cat/csw/2.0.2") ET.register_namespace("gmd", "http://www.isotc211.org/2005/gmd") ET.register_namespace("gco", "http://www.isotc211.org/2005/gco") urllib3.disable_warnings() http_proxy = os.environ.get('http_proxy') http = urllib3.proxy_from_url(http_proxy) if http_proxy else urllib3.PoolManager() def fetch_metadata_from_csw(catalogue): def get_request(): request_filename = catalogue[0] + "/request.xml" request_body = read_file(request_filename) return http.urlopen("POST", catalogue[1], headers={"Content-type": "text/xml"}, body=request_body) fetch_metadata(catalogue, get_request) def fetch_metadata_from_url(catalogue): def get_request(): return http.urlopen("GET", catalogue[1])
from config import * from telethon.tl.functions.photos import UploadProfilePhotoRequest, DeletePhotosRequest from datetime import datetime from utils import * import time import socks import urllib3 import socket from telethon import TelegramClient, sync api_id = 937111 api_hash = '0af7f3258d8a092d89f08a13031d7245' socks.set_default_proxy(socks.SOCKS5, "localhost") socket.socket = socks.socksocket urllib3.proxy_from_url("https://my.telegram.org") client = TelegramClient( 'first_session', api_id, api_hash, proxy=(socks.SOCKS5, 'PROXYHOST', 'PROXYUSERNAME', 'PROXYUSERNAMEPASS') ) # ИМЯ СЕССИИ можете выбрать любое, на свое усмотрение (например, «ананас») client.start() prev_update_time = "" while True: if time_has_changed(prev_update_time): prev_update_time = convert_time_to_string(datetime.now()) client(DeletePhotosRequest(client.get_profile_photos('me')))
except smtplib.SMTPException: logging.error("Error: unable to send email") if __name__ == '__main__': arguments = docopt(__doc__) logging.basicConfig(filename=arguments['--log-file'], level=logging.DEBUG, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') logging.info("*** Linux LTS Monitor Tool ***") distro_certs = discover_certs() if Path(distro_certs).is_file(): http = urllib3.proxy_from_url(os.environ['https_proxy'], cert_reqs='REQUIRED', ca_certs=distro_certs) elif Path(distro_certs).is_dir(): http = urllib3.proxy_from_url(os.environ['https_proxy'], cert_reqs='REQUIRED', ca_cert_dir=distro_certs) request = http.request('GET', kernel_xml_url) feed_data = feedparser.parse(request.data) current_lts_kernel = get_current_lts() for entry in feed_data['entries']: version = entry['title'].split(':')[0] build_type = entry['title'].split(' ')[1] if build_type == "longterm" and semver.match(version, '>' + current_lts_kernel):
def test_connect(self): proxy = urllib3.proxy_from_url(self.proxy_url) res = proxy.urlopen('GET', self.https_url) self.assertEqual(res.status, 200)
# ruleid:disabled-cert-validation manager = PoolManager(10, cert_reqs = ssl.CERT_OPTIONAL) # ruleid:disabled-cert-validation proxy = ur3.ProxyManager('http://localhost:3128/', cert_reqs = ssl.CERT_NONE) # ruleid:disabled-cert-validation pool = ur3.connectionpool.HTTPSConnectionPool(cert_reqs=ssl.CERT_OPTIONAL) # ruleid:disabled-cert-validation pool = ur3.connection_from_url('someurl', cert_reqs= ssl.CERT_NONE) # ruleid:disabled-cert-validation pool = ur3.connection_from_url('someurl', cert_reqs='NONE') # OK; invalid pool = ur3.connection_from_url('someurl', cert_reqs='CERT NONE') # ruleid:disabled-cert-validation pool = ur3.connection_from_url('someurl', cert_reqs="NONE") # ok pool = ur3.connection_from_url('someurl', cert_reqs= 'CERT_REQUIRED') # ruleid:disabled-cert-validation pool = ur3.proxy_from_url('someurl', cert_reqs= ssl.CERT_NONE) # ok pool = ur3.proxy_from_url('someurl', cert_reqs= ssl.CERT_REQUIED) # ok pool = ur3.proxy_from_url('someurl', cert_reqs=None)