def delete_repo(api_url, auth_token, repo_id):
req = urllib.request.Request(
url = api_url+'/repositories/'+str(repo_id),
data = None,
headers = {'X-ArchivesSpace-Session': auth_token},
method = 'DELETE')
try:
response = urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
print(e.code)
print(e.read())
return None
except urllib.error.URLError as e:
print(e.reason())
return None
src = response.read().decode('utf-8')
return json.JSONDecoder().decode(src)
Our test should look something like …
# Test delete_repo
print('Testing delete_repo()')
repo_id = int(input('Repository numeric id to delete: '))
result = delete_repo(api_url, auth_token, repo_id)
print('Result is', json.dumps(result, indent=4))
Full listing repo.py