Python requests.options() Examples

The following are 28 code examples of requests.options(). 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 also want to check out all available functions/classes of the module requests , or try the search function .
Example #1
Source File: cli.py    From web3-gear with MIT License 6 votes vote down vote up
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 #2
Source File: plex.py    From plex_autoscan with GNU General Public License v3.0 6 votes vote down vote up
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
Source File: plex.py    From plex_autoscan with GNU General Public License v3.0 6 votes vote down vote up
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
Source File: plex.py    From plex_autoscan with GNU General Public License v3.0 6 votes vote down vote up
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
Source File: verbal.py    From tactical-exploitation with MIT License 6 votes vote down vote up
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
Source File: uptest.py    From hsds with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: Options.py    From Medusa with GNU General Public License v3.0 6 votes vote down vote up
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 #8
Source File: test_local.py    From chalice with Apache License 2.0 5 votes vote down vote up
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 #9
Source File: test_api.py    From raiden-services with MIT License 5 votes vote down vote up
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 #10
Source File: test_local.py    From chalice with Apache License 2.0 5 votes vote down vote up
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 #11
Source File: test_yeti.py    From resilient-community-apps with MIT License 5 votes vote down vote up
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 #12
Source File: test_abuseipdb_service.py    From resilient-community-apps with MIT License 5 votes vote down vote up
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 #13
Source File: test_google_safe_browsing_threat_service.py    From resilient-community-apps with MIT License 5 votes vote down vote up
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 #14
Source File: test_have_i_been_pwned_threat_service.py    From resilient-community-apps with MIT License 5 votes vote down vote up
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 #15
Source File: util.py    From docassemble with MIT License 5 votes vote down vote up
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 #16
Source File: http.py    From habu with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #17
Source File: requests.py    From aki with GNU Affero General Public License v3.0 5 votes vote down vote up
def options(url, **kwargs) -> AsyncResponse:
    return AsyncResponse(
        await run_sync_func(requests.options, url=url, **kwargs)) 
Example #18
Source File: client.py    From eavatar-me with Apache License 2.0 5 votes vote down vote up
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 #19
Source File: aiorequests.py    From HoshinoBot with GNU General Public License v3.0 5 votes vote down vote up
def options(url, **kwargs) -> AsyncResponse:
    return AsyncResponse(
        await run_sync_func(requests.options, url=url, **kwargs)) 
Example #20
Source File: options_method.py    From onlinetools with MIT License 5 votes vote down vote up
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 #21
Source File: uri.py    From kalliope with GNU General Public License v3.0 5 votes vote down vote up
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 #22
Source File: app.py    From pipelines with Apache License 2.0 5 votes vote down vote up
def is_deployment_available(params):
    url = get_deployment_url(params)
    response = requests.options(url)
    return response.status_code == 200 
Example #23
Source File: check_webdav.py    From aemscan with MIT License 5 votes vote down vote up
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 #24
Source File: test_webserver.py    From resilient-python-api with MIT License 5 votes vote down vote up
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 #25
Source File: cors.py    From Astra with Apache License 2.0 5 votes vote down vote up
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 #26
Source File: sendrequest.py    From Astra with Apache License 2.0 5 votes vote down vote up
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 #27
Source File: mozie_request.py    From plugin.video.bimozie with GNU General Public License v3.0 5 votes vote down vote up
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 #28
Source File: openedx_appserver.py    From opencraft with GNU Affero General Public License v3.0 5 votes vote down vote up
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