Skip to content

Commit

Permalink
Use POST to export data as query may be too large to fit in URL (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
grotmol authored Dec 13, 2021
1 parent 13d2172 commit 675c654
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.1
2.0.2
10 changes: 7 additions & 3 deletions exabel_data_sdk/scripts/export_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import sys
from time import time
from typing import Sequence

import requests
Expand Down Expand Up @@ -58,10 +59,11 @@ def run(self) -> None:
args = self.parse_arguments()
login = CliLogin(args.auth0, args.client_id, args.backend)
login.log_in()
query = requests.utils.quote(args.query) # type: ignore[attr-defined]
headers = {"Authorization": f"Bearer {login.access_token}"}
url = f"https://{args.backend}/v1/export/file?format={args.format}&query={query}"
response = requests.get(url, headers=headers)
data = {"format": args.format, "query": args.query}
url = f"https://{args.backend}/v1/export/file"
start_time = time()
response = requests.post(url, headers=headers, data=data)
if response.status_code == 200:
with open(args.filename, "wb") as file:
file.write(response.content)
Expand All @@ -70,6 +72,8 @@ def run(self) -> None:
if error_message.startswith('"') and error_message.endswith('"'):
error_message = error_message[1:-1]
print(f"{response.status_code}: {error_message}")
spent_time = time() - start_time
print(f"Query completed in {int(spent_time)} seconds")


if __name__ == "__main__":
Expand Down

0 comments on commit 675c654

Please sign in to comment.