Hello team
We are using jira cloud instance (connecting with google account ).
I'm searching for script to download a backup every week , i find this one , im not expert in writing script , but when i execute this script i get this error :
Error
<Response [403]> Basic auth with password is not allowed on this instance
My python script :
import json
import time
import requests
from requests.auth import HTTPBasicAuth
def download_file(url, auth):
local_filename = "jira-export_{}.zip".format(time.strftime("%Y-%m-%d", time.gmtime()))
# NOTE the stream=True parameter
r = requests.get(url, stream=True, auth=auth)
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
return local_filename
JIRA_HOST = "ist-efr.atlassian.net"
URL_backup = "https://%(jira_host)s/rest/backup/1/export/runbackup" % {'jira_host': JIRA_HOST}
URL_download = "https://%(jira_host)s/plugins/servlet" % {'jira_host': JIRA_HOST}
# Since ~ mid 2019 Atlassian has been deprecated basic auth login:pass.
# You should use email:apitoken instead
auth = HTTPBasicAuth("_email", "_api_token")
payload = {"cbAttachments": "true", "exportToCloud": "false"}
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
def main():
backup_run = requests.post(URL_backup, data=json.dumps(payload), headers=headers, auth=auth)
if backup_run.status_code != 200:
print(backup_run, backup_run.text)
else:
task_id = json.loads(backup_run.text)['taskId']
print('Backup process successfully started ; taskid %s' % task_id)
URL_progress = "https://%(jira_host)s/rest/backup/1/export/getProgress?taskId=%(task_id)s&_=%(current_ts)s" % \
{'jira_host': JIRA_HOST,
'task_id': task_id,
'current_ts': int(round(time.time() * 1000))
}
time.sleep(10)
backup_status = {}
while "result" not in backup_status.keys():
backup_status = json.loads(requests.get(URL_progress, auth=auth).text)
print("Current status: {} {}; {}".format(backup_status['status'],
backup_status['progress'],
backup_status['description'] + ":" + backup_status['message']
)
)
time.sleep(120)
print("Downloading backup file")
try:
result = backup_status['result']
download_file(URL_download + "/%(fileName)s" % {'fileName': result},
auth)
except json.decoder.JSONDecodeError as e:
print('Something going wrong: %s' % e)
print('Last data: %s' % backup_status)
if __name__ == '__main__':
main()
Could some one help me
Thank you
Regards
Karim
Hi @karim -Atlassway- ,
This error is due to basic authentication with password being deprecated.
Deprecation of basic authentication with passwords for Jira and Confluence APIs
You'll have to create an api token and use that instead of your password.
Hello @Edwin Kyalangalilwa
First thank you for your response .
all scripts that I found do not works .
have you please one example ?
Thank you
regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hello @Edwin Kyalangalilwa
Thank you for your response
I used this for authentification
#!/usr/bin/python3.6
# library modules
from jira import JIRA
user = 'karim.belhadj@ovyka.com'
apikey = ''
server = 'https://ist-efr.atlassian.net'
options = {
'server': server
}
jira = JIRA(options, basic_auth=(user,apikey) )
# print all of the project keys as an example
for project in jira.projects():
print(project.key)
I get this error cannot import name 'JIRA' from 'jira'
Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've updated your reply above and removed your apikey. Please delete this key and generate a new one for security reasons.
First you'll have to install the library
Download and install using pip install jira or easy_install jira
Either using
pip install jira
or
easy_install jira
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.