How to clear settings using azure cli and rest command? - python

I want to remove settings from keyVaultReferenceIdentity
az rest --method PATCH --uri "${resourceId}?api-version=2021-01-01" --body "{""properties"":{""keyVaultReferenceIdentity"":null}}" --query properties.keyVaultReferenceIdentity -o json
But for this I have
Unsupported Media Type({"error":{"code":"UnsupportedMediaType","message":"The content media type '' is not supported. Only 'application/json' is supported."}})
If I add headers:
$headers = #{"Content-Type" = "application/json" }
az rest --method PATCH --Headers $headers --uri "${resourceId}?api-version=2021-01-01" --body "{""properties"":{""keyVaultReferenceIdentity"":null}}" --query properties.keyVaultReferenceIdentity -o json
then:
The command failed with an unexpected error. Here is the traceback:
not enough values to unpack (expected 2, got 1)
Traceback (most recent call last):
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py", line 506, in shell_safe_json_parse
File "json_init_.py", line 370, in loads
File "json\decoder.py", line 337, in decode
File "json\decoder.py", line 355, in raw_decode
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py", line 815, in send_raw_request
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py", line 531, in shell_safe_json_parse
azure.cli.core.azclierror.InvalidArgumentValueError: Failed to parse JSON: System.Collections.Hashtable
Error detail: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 231, in invoke
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 657, in execute
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 720, in _run_jobs_serially
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 691, in _run_job
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 328, in call
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/util/custom.py", line 16, in rest_call
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py", line 818, in send_raw_request
ValueError: not enough values to unpack (expected 2, got 1)
Idea is to clear keyVaultReferenceIdentity however I can find valid syntax and parameters combination.
I found this issue on GH but it didn't help.

I did a repro with your CLI command and modified according to correct format and fixed, below is the CLI command where we can execute it without getting any errors.
az rest --method patch --headers "{'Content-Type':
'application/json'}" --uri
/subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP_NAME/providers/Microsoft.Web/sites/CheckingLogs0805?api-version=2015-08-01
--body "{'properties': {'siteConfig': {'keyVaultReferenceIdentity':null}}}" --query
properties.keyVaultReferenceIdentity -o json
So, above command will fix the error messages which you have shown (i.e., UnsupportedMediaType and JSONDecodeError
Now coming to the question to clear the value of 'keyVaultReferenceIdentity'. This usually sets by default while creation as SystemAssigned. These values are taken from Managed Identities.
Please check the documentation for the values System Identity and Managed Identity.
From the command which I have fixed, we can change the value of any other parameter.
Refer to screenshot as I have changed value of 'properties': {"enabled": true}

Related

openapi-python-client write-only field is required in GET request

i'm using DRF+openapi-python-client for my project.
i have 2 question for now.
openapi-python-client generate does not accept url for generating client
generated client fileas to serialize model having write-only file field
Thanx in advance!
Launching my server with manage.py script works ok, i can get my openapi schema on http://127.0.0.1:8000/control_center/schema/?format=openapi-json with my browser. On the same time,command openapi-python-client generate --url http://localhost:8000/control_center/schema?format=openapi-json gives me
Traceback (most recent call last):
File "pydantic/main.py", line 522, in pydantic.main.BaseModel.parse_obj
TypeError: 'NoneType' object is not iterable
What am i missing? workaround for me is to copy schema from browser to json and run openapi-python-client generate --path schema.json
i have a model StorageFile with write-only file field. In GET responses this field is ommited,getting file content is another endpoint. Getting storage file details with browser or with manual request is ok,but using generated client like
file_details: models.StorageFile = retrieve_storage_file.sync(id=file.id,
client=self.api_client)
gives me error
Error
Traceback (most recent call last):
File ".../api_client_tests/test_storage_files_api.py", line 18, in test_can_get_storage_file_details
file_details: models.StorageFile = retrieve_storage_file.sync(id=file.id,
File ".../api_client/control_center_client/control_center_client/api/control_center/retrieve_storage_file.py", line 86, in sync
return sync_detailed(
File ".../api_client/control_center_client/control_center_client/api/control_center/retrieve_storage_file.py", line 70, in sync_detailed
return _build_response(response=response)
File ".../api_client/control_center_client/control_center_client/api/control_center/retrieve_storage_file.py", line 43, in _build_response
parsed=_parse_response(response=response),
File ".../api_client/control_center_client/control_center_client/api/control_center/retrieve_storage_file.py", line 32, in _parse_response
response_200 = StorageFile.from_dict(response.json())
File ".../api_client/control_center_client/control_center_client/models/storage_file.py", line 128, in from_dict
file = File(payload=BytesIO(d.pop("file")))
KeyError: 'file'
In schem.json this field is described as
"file": {
"type": "string",
"format": "binary",
"writeOnly": true
}
What am i missing here?

Getting OSError when running script

I am trying to set up the ChirpSDK, but every time I configure and run the code, I get this error:
Traceback (most recent call last):
File "test.py", line 3, in <module>
chirp = ChirpSDK()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 395, in __init__
self.read_chirprc(block)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 501, in read_chirprc
raise IOError('Could not find a ~/.chirprc file')
OSError: Could not find a ~/.chirprc file
Exception ignored in: <function ChirpSDK.__del__ at 0x10fa31af0>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 422, in __del__
self.close()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 470, in close
if self._sdk:
AttributeError: 'ChirpSDK' object has no attribute '_sdk'
I realize that the error is saying that my .chirprc file is not being recognized, but I have no idea how to remedy this. I created a .chirprc file in my /Users/username/ path, and named it c.chirprc (as the Chirp getting started article suggests), but I am still getting this error. Is there another part that I am missing? Am I reading the instructions wrong?
Thanks
The Chirp configuration file should be placed at /Users/<username>/.chirprc on macOS.
If you run ls -l ~/.chirprc in the terminal, do you get any results? If it displays no such file or directory then you have not created the file correctly.

Difficulty creating an XLSM file

I'm trying to create an xlsm file using xlwings. Or openpyxl if not possible with xlwings.
I'm on Mac so I can't use PyWin32.
I'm running the following python code:
import xlwings as xw
b = xw.Book()
b.save('test_book2.xlsm')
When I run that code I receive the message:
When I click 'yes' to that message I receive the following error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/aeosa/appscript/reference.py", line 482, in __call__
return self.AS_appdata.target().event(self._code, params, atts, codecs=self.AS_appdata).send(timeout, sendflags)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/aeosa/aem/aemsend.py", line 92, in send
raise EventError(errornum, errormsg, eventresult)
aem.aemsend.EventError: Command failed: Parameter error. (-50)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/matthewbell/Desktop/test.py", line 4, in <module>
b.save('test_book2.xlsm')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xlwings/main.py", line 704, in save
return self.impl.save(path)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xlwings/_xlmac.py", line 244, in save
self.xl.save_workbook_as(filename=hfs_path, overwrite=True)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/aeosa/appscript/reference.py", line 518, in __call__
raise CommandError(self, (args, kargs), e, self.AS_appdata) from e
appscript.reference.CommandError: Command failed:
OSERROR: -50
MESSAGE: Parameter error.
COMMAND: app(pid=6198).workbooks['Book1'].save_workbook_as(filename='Macintosh HD:Users:matthewbell:Desktop:test_book2.xlsm', overwrite=True)
What can I do to create an xlsm file?

Python code not working from cron job but works from command line via virtualenv

I am receiving different errors which I cannot determine the issue. It seems as though it has to do with the configparser.py NoSectionError(section). This code runs fine from the command line in the virtualenv.
Traceback (most recent call last):
File "/usr/lib/python3.5/configparser.py", line 1135, in _unify_values
sectiondict = self._sections[section]
KeyError: 'token'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/lvensel/projects/worklion01/worklion01/wl_cron.py", line 15, in <module>
wl_post_projects.post()
File "/home/lvensel/projects/worklion01/worklion01/wl_post_projects.py", line 15, in post
import wl_get_background_jobs
File "/home/lvensel/projects/worklion01/worklion01/wl_get_background_jobs.py", line 12, in <module>
oauth, token = wl_secure_token.fetch_token()
File "/home/lvensel/projects/worklion01/worklion01/wl_secure_token.py", line 17, in fetch_token
values = wl_get_ini.get_values()
File "/home/lvensel/projects/worklion01/worklion01/wl_get_ini.py", line 13, in get_values
'token_url': config.get('token', 'token_url'),
File "/usr/lib/python3.5/configparser.py", line 778, in get
d = self._unify_values(section, vars)
File "/usr/lib/python3.5/configparser.py", line 1138, in _unify_values
raise NoSectionError(section)
configparser.NoSectionError: No section: 'token'
Let me guess on what potentially happens:
Cron jobs are run by root
virtualenv is run by your user with a custom python environment.
root does not know about your virtualenv, then cannot match your user's python environment, thus your script fails. Probably with some cannot import or alike errors.
Have a look at replies here.

HTTP header error using the Python SDK for Azure

I am starting with Microsoft Azure SDK for Python (https://github.com/Azure/azure-sdk-for-python), but I have problems.
I am using Scientific Linux and I have installed the SDK for Python 3.4 following the next steps:
(instead of the SDK directory)
python setup.py install
after that I created a simple script just to test the connection:
from azure.storage import BlobService
blob_service = BlobService(account_name='thename', account_key='Mxxxxxxx3w==' )
blob_service.create_container('testcontainer')
for i in blob_service.list_containers():
print(i.name)
following this documentation:
http://blogs.msdn.com/b/tconte/archive/2013/04/17/how-to-interact-with-windows-azure-blob-storage-from-linux-using-python.aspx
http://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/#large-blobs
but is not working, I always receive the same error:
python3 test.py
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/azure-0.9.0-py3.4.egg/azure/storage/storageclient.py", line 143, in _perform_request
File "/usr/local/lib/python3.4/site-packages/azure-0.9.0-py3.4.egg/azure/storage/storageclient.py", line 132, in _perform_request_worker
File "/usr/local/lib/python3.4/site-packages/azure-0.9.0-py3.4.egg/azure/http/httpclient.py", line 247, in perform_request
azure.http.HTTPError: The value for one of the HTTP headers is not in the correct format.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 21, in <module>
blob_service.create_container('testcontainer')
File "/usr/local/lib/python3.4/site-packages/azure-0.9.0-py3.4.egg/azure/storage/blobservice.py", line 192, in create_container
File "/usr/local/lib/python3.4/site-packages/azure-0.9.0-py3.4.egg/azure/__init__.py", line 905, in _dont_fail_on_exist
File "/usr/local/lib/python3.4/site-packages/azure-0.9.0-py3.4.egg/azure/storage/blobservice.py", line 189, in create_container
File "/usr/local/lib/python3.4/site-packages/azure-0.9.0-py3.4.egg/azure/storage/storageclient.py", line 150, in _perform_request
File "/usr/local/lib/python3.4/site-packages/azure-0.9.0-py3.4.egg/azure/storage/__init__.py", line 889, in _storage_error_handler
File "/usr/local/lib/python3.4/site-packages/azure-0.9.0-py3.4.egg/azure/__init__.py", line 929, in _general_error_handler
azure.WindowsAzureError: Unknown error (The value for one of the HTTP headers is not in the correct format.)
<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidHeaderValue</Code><Message>The value for one of the HTTP headers is not in the correct format.
RequestId:b37c5584-0001-002b-24b8-c2c245000000
Time:2014-11-19T14:54:38.9378626Z</Message><HeaderName>x-ms-version</HeaderName><HeaderValue>2012-02-12</HeaderValue></Error>
Thanks in advance and best regards.
I have this exact same issue. I believe it's a library bug, but the author/s haven't had their say yet.
It looks like the response states the version, but it's actually giving you the header that's wrong. Its value should be "2014-02-14", you can do the fix shown in https://github.com/Azure/azure-sdk-for-python/pull/289 .
Hopefully this will be fixed and nobody will ever read this answer. Cheers!

Categories

Resources