Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'requests' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
int a; cin >> a;
int b, c; cin >> b >> c;
string s; cin >> s;
cout << a + b + c << ' ' << s << endl;
return 0;
}
'''
files = [
{
'path': 'main.cpp',
'data': code
},
]
with tests.utils.sandbox(files):
with self.assertRaises(requests.exceptions.HTTPError):
args = ["submit", '-y', '--no-open', url, 'main.cpp']
args = get_parser().parse_args(args=args)
submit(args)
def test_url_prefix():
url = "http://127.0.0.1:5000"
meta = requests.get(url, headers={'Accept': 'application/json'}).json()
url_prefix, __, __ = parse_meta(meta)
assert url_prefix == ""
def test_POST_pass(self):
results_url = '%srecipes/%s/tasks/%s/results/' % (self.get_proxy_url(),
self.recipe.id, self.recipe.tasks[0].id)
response = requests.post(results_url, data=dict(result='Pass',
path='/random/junk', score='123', message='The thing worked'))
self.assertEquals(response.status_code, 201)
self.assert_(response.headers['Location'].startswith(results_url),
response.headers['Location'])
result_id = int(posixpath.basename(response.headers['Location']))
self.check_result(result_id, TaskResult.pass_, u'/random/junk', 123,
u'The thing worked')
@responses.activate
def test_check_basic_auth_tomcat_fail(self):
responses.add(** mock.tomcat_fp)
responses.add(** mock.tomcat_fp_alt)
cred = self.get_cred(self.tomcat_name)
assert cred['name'] == self.tomcat_name
changeme.logger = changeme.setup_logging(False, False, None)
s = requests.Session()
matches = changeme.check_basic_auth(mock.tomcat_fp['url'], s, cred, self.config, False, False)
assert len(matches) == 0
def _wait_for_s3(self):
while True:
time.sleep(1)
try:
requests.get("http://localhost:{}".format(self.port))
break
except requests.exceptions.ConnectionError:
print("waiting for container to become ready", self)
print("container ready, waiting another 5 seconds to ensure everything is set up")
time.sleep(5)
def create_test_user(cfg):
data = {'username': ADMIN_USERNAME, 'password': ADMIN_PASSWORD, }
res = requests.post(apiurl('/auth-token/'), data=data)
debug('%s %s', res.status_code, res.text)
token = res.json()['token']
data = {'password': PASSWORD, }
headers = {'Authorization': 'Token ' + token}
res = requests.put(
apiurl('/accounts/{}/'.format(USERNAME)),
data=data,
headers=headers)
assert res.status_code == 201
def _send_request(method, url, params, data, **settings):
if method == TestMethod.GET:
return requests.get(url=url, params=params, **settings)
elif method == TestMethod.PUT:
return requests.put(url=url, data=data, **settings)
elif method == TestMethod.POST:
return requests.post(url=url, data=data, **settings)
elif method == TestMethod.PATCH:
return requests.patch(url=url, data=data, **settings)
elif method == TestMethod.DELETE:
return requests.delete(url=url, **settings)
else:
raise UnsupportedMethodError('Unsupported method: %s' % method)
def test_03_rdm_portmapping(self):
url = ("{}/config/transportpce-portmapping:network/"
"nodes/ROADMA01"
.format(self.restconf_baseurl))
headers = {'content-type': 'application/json'}
response = requests.request(
"GET", url, headers=headers, auth=('admin', 'admin'))
self.assertEqual(response.status_code, requests.codes.ok)
res = response.json()
self.assertIn(
{'supporting-port': 'L1', 'supporting-circuit-pack-name': '2/0',
'logical-connection-point': 'DEG1-TTP-TXRX', 'port-direction': 'bidirectional'},
res['nodes'][0]['mapping'])
self.assertIn(
{'supporting-port': 'C7', 'supporting-circuit-pack-name': '4/0',
'logical-connection-point': 'SRG1-PP7-TXRX', 'port-direction': 'bidirectional'},
res['nodes'][0]['mapping'])
#Delete in the topology-netconf
url = ("{}/config/network-topology:"
"network-topology/topology/topology-netconf/node/ROADMC01"
.format(self.restconf_baseurl))
data = {}
headers = {'content-type': 'application/json'}
response = requests.request(
"DELETE", url, data=json.dumps(data), headers=headers,
auth=('admin', 'admin'))
self.assertEqual(response.status_code, requests.codes.ok)
#Delete in the clli-network
url = ("{}/config/ietf-network:networks/network/clli-network/node/NodeC"
.format(self.restconf_baseurl))
data = {}
headers = {'content-type': 'application/json'}
response = requests.request(
"DELETE", url, data=json.dumps(data), headers=headers,
auth=('admin', 'admin'))
self.assertEqual(response.status_code, requests.codes.ok)
headers=HA_HEADERS)
self.assertEqual(422, req.status_code)
# Setup a real one
req = requests.post(
_url(const.URL_API_EVENT_FORWARD),
data=json.dumps({
'api_password': API_PASSWORD,
'host': '127.0.0.1',
'port': SERVER_PORT
}),
headers=HA_HEADERS)
self.assertEqual(200, req.status_code)
# Delete it again..
req = requests.delete(
_url(const.URL_API_EVENT_FORWARD),
data=json.dumps({}),
headers=HA_HEADERS)
self.assertEqual(400, req.status_code)
req = requests.delete(
_url(const.URL_API_EVENT_FORWARD),
data=json.dumps({
'host': '127.0.0.1',
'port': 'abcd'
}),
headers=HA_HEADERS)
self.assertEqual(422, req.status_code)
req = requests.delete(
_url(const.URL_API_EVENT_FORWARD),