Skip to content

Commit c86f49e

Browse files
author
Rafa de la Torre
committed
Remove confusing usage of filename request param
1 parent d853350 commit c86f49e

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

doc/copy_queries.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -204,28 +204,20 @@ The Python to "copy to" is very simple, because the HTTP call is a simple get. T
204204

205205
```python
206206
import requests
207-
import re
208207

209208
api_key = {api_key}
210209
username = {api_key}
211-
download_file = 'upload_example_dl.csv'
210+
download_filename = 'download_example.csv'
212211
q = "COPY upload_example (the_geom, name, age) TO stdout WITH (FORMAT csv, HEADER true)"
213212

214-
# request the download, specifying desired file name
213+
# request the download
215214
url = "http://%s.carto.com/api/v2/sql/copyto" % username
216-
r = requests.get(url, params={'api_key': api_key, 'q': q, 'filename': download_file}, stream=True)
215+
r = requests.get(url, params={'api_key': api_key, 'q': q}, stream=True)
217216
r.raise_for_status()
218217

219-
# read save file name from response headers
220-
d = r.headers['content-disposition']
221-
savefilename = re.findall("filename=(.+)", d)
222-
223-
if len(savefilename) > 0:
224-
with open(savefilename[0], 'wb') as handle:
225-
for block in r.iter_content(1024):
226-
handle.write(block)
227-
print("Downloaded to: %s" % savefilename)
228-
else:
229-
print("Error: could not find read file name from headers")
218+
with open(download_filename, 'wb') as handle:
219+
for block in r.iter_content(1024):
220+
handle.write(block)
221+
print("Downloaded to: %s" % savefilename)
230222
```
231223

0 commit comments

Comments
 (0)