Python requests.options() Examples
The following are 28 code examples for showing how to use requests.options(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
requests
, or try the search function
.
Example 1
Project: hsds Author: HDFGroup File: uptest.py License: Apache License 2.0 | 6 votes |
def testCorsGetAbout(self): endpoint = helper.getEndpoint() print("endpoint:", endpoint) req = endpoint + "/about" rsp = requests.options( req, headers={ "Access-Control-Request-Method": "GET", "Origin": "*", "Access-Control-Request-Headers": "Authorization", }, ) self.assertEqual(rsp.status_code, 200) # cross origin allowed by default self.assertEqual(rsp.headers["Access-Control-Allow-Origin"], "*") self.assertEqual( rsp.headers["Access-Control-Allow-Methods"], "GET", )
Example 2
Project: plex_autoscan Author: l3uddz File: plex.py License: GNU General Public License v3.0 | 6 votes |
def split_plex_item(config, metadata_item_id): try: url_params = { 'X-Plex-Token': config['PLEX_TOKEN'] } url_str = '%s/library/metadata/%d/split' % (config['PLEX_LOCAL_URL'], int(metadata_item_id)) # send options request first (webui does this) requests.options(url_str, params=url_params, timeout=30) resp = requests.put(url_str, params=url_params, timeout=30) if resp.status_code == 200: logger.info("Successfully split 'metadata_item_id': '%d'", int(metadata_item_id)) return True else: logger.error("Failed splitting 'metadata_item_id': '%d'... Response =\n%s\n", int(metadata_item_id), resp.text) except Exception: logger.exception("Exception splitting 'metadata_item' %d: ", int(metadata_item_id)) return False
Example 3
Project: plex_autoscan Author: l3uddz File: plex.py License: GNU General Public License v3.0 | 6 votes |
def match_plex_item(config, metadata_item_id, new_guid, new_name): try: url_params = { 'X-Plex-Token': config['PLEX_TOKEN'], 'guid': new_guid, 'name': new_name, } url_str = '%s/library/metadata/%d/match' % (config['PLEX_LOCAL_URL'], int(metadata_item_id)) requests.options(url_str, params=url_params, timeout=30) resp = requests.put(url_str, params=url_params, timeout=30) if resp.status_code == 200: logger.info("Successfully matched 'metadata_item_id' '%d' to '%s' (%s).", int(metadata_item_id), new_name, new_guid) return True else: logger.error("Failed matching 'metadata_item_id' '%d' to '%s': %s... Response =\n%s\n", int(metadata_item_id), new_name, new_guid, resp.text) except Exception: logger.exception("Exception matching 'metadata_item' %d: ", int(metadata_item_id)) return False
Example 4
Project: plex_autoscan Author: l3uddz File: plex.py License: GNU General Public License v3.0 | 6 votes |
def refresh_plex_item(config, metadata_item_id, new_name): try: url_params = { 'X-Plex-Token': config['PLEX_TOKEN'], } url_str = '%s/library/metadata/%d/refresh' % (config['PLEX_LOCAL_URL'], int(metadata_item_id)) requests.options(url_str, params=url_params, timeout=30) resp = requests.put(url_str, params=url_params, timeout=30) if resp.status_code == 200: logger.info("Successfully refreshed 'metadata_item_id' '%d' of '%s'.", int(metadata_item_id), new_name) return True else: logger.error("Failed refreshing 'metadata_item_id' '%d' of '%s': Response =\n%s\n", int(metadata_item_id), new_name, resp.text) except Exception: logger.exception("Exception refreshing 'metadata_item' %d: ", int(metadata_item_id)) return False
Example 5
Project: tactical-exploitation Author: 0xdea File: verbal.py License: MIT License | 6 votes |
def scan_options(url, timeout): """ OPTIONS method scanner """ try: r = requests.options( url=url, timeout=timeout, verify=False) print( " OPTIONS" + "\t> " + str(r.status_code) + " (" + str(requests.status_codes._codes[r.status_code][0]) + ")") print(" " + "Methods: " + r.headers["allow"]) except (KeyboardInterrupt, SystemExit): sys.exit(1) except Exception as err: pass # ignore errors
Example 6
Project: Medusa Author: Ascotbe File: Options.py License: GNU General Public License v3.0 | 6 votes |
def medusa(Url:str,RandomAgent:str,proxies:str=None,**kwargs)->None: proxies=Proxies().result(proxies) scheme, url, port = UrlProcessing().result(Url) try: payload_url = Url headers = { 'User-Agent': RandomAgent, "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Encoding": "gzip, deflate", } resp = requests.options(payload_url,headers=headers,proxies=proxies, timeout=5, verify=False) if r"OPTIONS" in resp.headers.get('Allow'): Medusa = "{}存在Options方法开启漏洞\r\n验证数据:\r\n漏洞位置:{}\r\n漏洞详情:{}\r\n".format(url,payload_url,resp.headers) _t = VulnerabilityInfo(Medusa) VulnerabilityDetails(_t.info, url,**kwargs).Write() # 传入url和扫描到的数据 WriteFile().result(str(url),str(Medusa))#写入文件,url为目标文件名统一传入,Medusa为结果 except Exception as e: _ = VulnerabilityInfo('').info.get('algroup') ErrorHandling().Outlier(e, _) _l = ErrorLog().Write("Plugin Name:"+_+" || Target Url:"+url,e)#调用写入类
Example 7
Project: web3-gear Author: vechain File: cli.py License: MIT License | 6 votes |
def run_server(host, port, endpoint, keystore, passcode, log, debug): try: response = requests.options(endpoint) response.raise_for_status() except requests.exceptions.ConnectionError: print("Unable to connect to Thor-Restful server.") return print(make_version()) print("Listening on %s:%s" % (host, port)) thor.set_endpoint(endpoint) if keystore == "": thor.set_accounts(solo()) else: thor.set_accounts(_keystore(keystore, passcode)) app = web.Application() app.router.add_post("/", lambda r: handle(r, log, debug)) app.router.add_options("/", lambda r: web.Response(headers=res_headers)) web.run_app(app, host=host, port=port)
Example 8
Project: opencraft Author: open-craft File: openedx_appserver.py License: GNU Affero General Public License v3.0 | 5 votes |
def heartbeat_active(self): """Is this server's /heartbeat running ok (returning code < 400)""" try: return requests.options('http://{}/heartbeat'.format(self.server.public_ip)).ok except requests.exceptions.ConnectionError: return False
Example 9
Project: plugin.video.bimozie Author: billythekids File: mozie_request.py License: GNU General Public License v3.0 | 5 votes |
def options(self, url, params=None, headers=None, redirect=True, cookies=None, verify=True): # if headers: # headers = self.DEFAULT_HEADERS.update(headers) if self.session: self.r = self.session.options(url, headers=headers, timeout=self.TIMEOUT, params=params, allow_redirects=redirect, verify=verify) else: self.r = requests.options(url, headers=headers, timeout=self.TIMEOUT, params=params, allow_redirects=redirect) return self.r
Example 10
Project: Astra Author: flipkart-incubator File: sendrequest.py License: Apache License 2.0 | 5 votes |
def api_request(url,method,headers,body=None): try: if method.upper() == "GET": auth_request = requests.get(url,headers=headers, allow_redirects=False,verify=False) elif method.upper() == "POST": auth_request = requests.post(url,headers=headers,json=body, allow_redirects=False,verify=False) elif method.upper() == "PUT": auth_request = requests.put(url,headers=headers,data=body, allow_redirects=False,verify=False) elif method.upper() == "OPTIONS": auth_request = requests.options(url,headers=headers, verify=False) return auth_request except Exception as e: logs.logging.error("Exception from sendrequest %s",e)
Example 11
Project: Astra Author: flipkart-incubator File: cors.py License: Apache License 2.0 | 5 votes |
def check_custom_header(url, header_name): # Check if custom header is allowed to send. request_header = {'Access-Control-Request-Headers' : header_name} req_custom_header = requests.options(url, header_name,verify=False) try: if req_custom_header.headers['Access-Control-Allow-Headers'] == header_name: return True else: return False except: return False
Example 12
Project: resilient-python-api Author: ibmresilient File: test_webserver.py License: MIT License | 5 votes |
def test_options(self, circuits_app, new_incident): """Verify the web service is responding to the OPTIONS method""" #WebTest({}).register(circuits_app.app.component_loader) response = requests.options(SERVICE_URL) assert response.status_code == 200
Example 13
Project: aemscan Author: Raz0r File: check_webdav.py License: MIT License | 5 votes |
def run(url): response = requests.options(url + '/') if 'propfind' in response.headers.get('allow', '').lower() or response.status_code == 401: click.echo(click.style('WebDAV is enabled', fg='green')) else: click.echo(click.style('WebDAV is disabled', fg='red'))
Example 14
Project: pipelines Author: kubeflow File: app.py License: Apache License 2.0 | 5 votes |
def is_deployment_available(params): url = get_deployment_url(params) response = requests.options(url) return response.status_code == 200
Example 15
Project: kalliope Author: kalliope-project File: uri.py License: GNU General Public License v3.0 | 5 votes |
def do_options(self): logger.debug(self.neuron_name + " do_options method called") r = requests.options(url=self.url, **self.parameters) self.post_processing_request(r)
Example 16
Project: raiden-services Author: raiden-network File: test_api.py License: MIT License | 5 votes |
def test_cors(api_url: str): headers = { "Origin": "http://example.com/", "Access-Control-Request-Method": "GET", "Access-Control-Request-Headers": "X-Requested-With", } response = requests.options(api_url, headers=headers) assert response.headers["Access-Control-Allow-Origin"] == "*" assert response.headers["Access-Control-Allow-Headers"] == "Origin, Content-Type, Accept"
Example 17
Project: onlinetools Author: iceyhexman File: options_method.py License: MIT License | 5 votes |
def run(self): headers = { "User-Agent":"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50" } vulnurl = self.url try: req = requests.options(vulnurl, headers=headers, timeout=10, verify=False) if r"OPTIONS" in req.headers['Allow']: return "[+]存在options方法开启...(敏感信息)"+"\tpayload: "+vulnurl+"\tAllow:"+req.headers['Allow'] else: return "[-]NO vuln!" except: return "[-] ======>连接超时"
Example 18
Project: HoshinoBot Author: Ice-Cirno File: aiorequests.py License: GNU General Public License v3.0 | 5 votes |
def options(url, **kwargs) -> AsyncResponse: return AsyncResponse( await run_sync_func(requests.options, url=url, **kwargs))
Example 19
Project: eavatar-me Author: eavatar File: client.py License: Apache License 2.0 | 5 votes |
def options(self, uri, params=None, headers=None): if headers is None: headers = dict() headers.update(self._headers) return requests.options(self._url + uri, params=params, headers=headers)
Example 20
Project: chalice Author: aws File: test_local.py License: Apache License 2.0 | 5 votes |
def test_can_accept_options_request(config, sample_app, local_server_factory): local_server, port = local_server_factory(sample_app, config) response = local_server.make_call(requests.options, '/test-cors', port) assert response.headers['Content-Length'] == '0' assert response.headers['Access-Control-Allow-Methods'] == 'POST,OPTIONS' assert response.text == ''
Example 21
Project: chalice Author: aws File: test_local.py License: Apache License 2.0 | 5 votes |
def test_can_accept_multiple_options_request(config, sample_app, local_server_factory): local_server, port = local_server_factory(sample_app, config) response = local_server.make_call(requests.options, '/test-cors', port) assert response.headers['Content-Length'] == '0' assert response.headers['Access-Control-Allow-Methods'] == 'POST,OPTIONS' assert response.text == '' response = local_server.make_call(requests.options, '/test-cors', port) assert response.headers['Content-Length'] == '0' assert response.headers['Access-Control-Allow-Methods'] == 'POST,OPTIONS' assert response.text == ''
Example 22
Project: resilient-community-apps Author: ibmresilient File: test_yeti.py License: MIT License | 5 votes |
def test_options(self, circuits_app): """Verify the web service is responding to the OPTIONS method""" response = requests.options(SERVICE_URL) assert response.status_code == 200
Example 23
Project: resilient-community-apps Author: ibmresilient File: test_abuseipdb_service.py License: MIT License | 5 votes |
def test_options(self, circuits_app): """Verify the web service is responding to the OPTIONS method""" response = requests.options(SERVICE_URL) assert response.status_code == 200
Example 24
Project: resilient-community-apps Author: ibmresilient File: test_google_safe_browsing_threat_service.py License: MIT License | 5 votes |
def test_options(self, circuits_app): """Verify the web service is responding to the OPTIONS method""" response = requests.options(SERVICE_URL) assert response.status_code == 200
Example 25
Project: resilient-community-apps Author: ibmresilient File: test_have_i_been_pwned_threat_service.py License: MIT License | 5 votes |
def test_options(self, circuits_app): """Verify the web service is responding to the OPTIONS method""" response = requests.options(SERVICE_URL) assert response.status_code == 200
Example 26
Project: docassemble Author: jhpyle File: util.py License: MIT License | 5 votes |
def options(self, url, data=None, params=None, headers=None, json_body=None, on_failure=None, on_success=None, auth=None, cookies=None, task=None): """Makes an OPTIONS request""" return self._call(url, method='OPTIONS', data=data, params=params, headers=headers, json_body=json_body, on_failure=on_failure, on_success=on_success, auth=auth, cookies=cookies, task=task)
Example 27
Project: habu Author: fportantier File: http.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_options(server): """Retrieve the available HTTP verbs""" try: response = requests.options( server, allow_redirects=False, verify=False, timeout=5) except (requests.exceptions.ConnectionError, requests.exceptions.MissingSchema): return "Server {} is not available!".format(server) try: return {'allowed': response.headers['Allow']} except KeyError: return "Unable to get HTTP methods"
Example 28
Project: aki Author: cczu-osa File: requests.py License: GNU Affero General Public License v3.0 | 5 votes |
def options(url, **kwargs) -> AsyncResponse: return AsyncResponse( await run_sync_func(requests.options, url=url, **kwargs))