Home
Help
Search
Login
Register
OPNsense Forum
»
English Forums
»
General Discussion
»
OPNsense Backup with Python
« previous
next »
Print
Pages: [
1
]
Author
Topic: OPNsense Backup with Python (Read 824 times)
And1
Newbie
Posts: 5
Karma: 0
OPNsense Backup with Python
«
on:
October 17, 2023, 01:44:23 pm »
Hey,
I've recently started working with OPNsense. It's a larger project, and one part of it involves using a Python script to pull a backup of the current settings, which should then be available as an XML file. I already have this code:
python
Copy code
def backup():
try:
params = {'format': 'plain'}
backup_url = f'{base_url}/backup/backup/download'
try:
response = requests.get(backup_url, auth = (api_key, api_secret), params=params, verify=False)
except Exception as error:
print(f'Error: {error}')
if response.status_code == 200:
with open('test_backup.xml', 'wb') as file:
file.write(response.content)
print("Backup successfully downloaded.")
else:
print(f"Error downloading the backup. Status code: {response.status_code}")
except Exception as e:
print(f'Error: {e}')
pass
The API key, API secret, and the base URL are declared outside of the function. However, when I execute the code, I always receive a status code of 401. Can someone help me with my little script, or are there completely different approaches to implement this with Python? Please accept that im new in OPNsense, ff I've simply made a silly mistake, please forgive me. I hope someone can assist me. Thank you very much in advance.
And1
Logged
And1
Newbie
Posts: 5
Karma: 0
Re: OPNsense Backup with Python
«
Reply #1 on:
October 19, 2023, 08:35:55 am »
i solved it, the code is correct, but the backup_url must be: f'{base_url}/backup/backup/download/?format=plain'
Greetings
And1
Logged
Print
Pages: [
1
]
« previous
next »
OPNsense Forum
»
English Forums
»
General Discussion
»
OPNsense Backup with Python