gregorycox-cv
6 months agoLevel 1
updating bandwidth for connection
I'm attempting to change the bandwidth using python requests
url = f"https://api.equinix.com/fabric/v4/connections/{cid}"
headers["content-type"] = 'application/json-patch+json'
response = requests.patch(
url,
headers=headers,
timeout=5,
data=[
{
"op": "replace",
"path": "/bandwidth",
"value": bw
}
]
if run as above I get this error
Traceback (most recent call last):
File "/Users/gregcox/Projects/app/main.py", line 238, in <module>
pp(update_bandwidth(vcs[0], 200))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gregcox/Projects/app/main.py", line 208, in update_bandwidth
response = requests.patch(
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/api.py", line 145, in patch
return request("patch", url, data=data, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 575, in request
prep = self.prepare_request(req)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 486, in prepare_request
p.prepare(
File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 371, in prepare
self.prepare_body(data, files, json)
File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 559, in prepare_body
body = self._encode_params(data)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 121, in _encode_params
for k, vs in to_key_val_list(data):
^^^^^
ValueError: too many values to unpack (expected 2)
If I run the same as above, but change data to be a dict instead of a list I get this error
[{'correlationId': '-api',
'details': 'Please refer the contracts for correct fields',
'errorCode': 'EQ-3142558',
'errorMessage': 'Json syntax error, please check request body'}]