What am I doing:
1.Get Base Access Token - work
2.Export A Base - work
3.Download Exported File with Task ID - does not work and gives “Permission denied.” Despite the fact that I can download the file using a direct link in the browser (if authorized).
I’ve tried using “with requests.Session () as session:” and even reading and passing cookies = {‘dtable_csrftoken’: xxx, ‘sessionid’: yyy} but it didn’t work.
Tell me how to download the database file in python correctly?
import requests
import json
host = "https://table.mhpost.ru"
url = f"{host}/api2/auth-token/"
payload = {
'username': 'xxx',
'password': 'yyy'
}
headers = {
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
token = json.loads(response.text)['token']
table_name = 'Brands CRM'
url = f"{host}/api/v2.1/workspace/1/dtable/{table_name}/export-dtable/"
payload = {}
headers = {
'Authorization': f'Token {token}',
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
task_id = json.loads(response.text)['task_id']
dtable_uuid = json.loads(response.text)['table']['uuid']
url = f"{host}/dtable-export-content/?task_id={task_id}&dtable_uuid={dtable_uuid}"
payload = {}
headers = {
'Authorization': f'Token {token}'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)