Skip to content

Commit d75139a

Browse files
committed
Fixes for write api - test system changes still dependend on TIND
1 parent 872dd3f commit d75139a

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

caltechdata_api/caltechdata_write.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json, copy
44
import os
55

6-
def send_s3(filepath,token,production=False):
6+
def send_s3(filepath,token,production=False,auth=None):
77

88
if production == True:
99
s3surl = "https://data.caltech.edu/tindfiles/sign_s3/"
@@ -16,7 +16,9 @@ def send_s3(filepath,token,production=False):
1616

1717
c = session()
1818

19-
response = c.get(s3surl,headers=headers)
19+
print(s3surl)
20+
print(headers)
21+
response = c.get(s3surl,headers=headers,auth=auth)
2022
jresp = response.json()
2123
data = jresp['data']
2224

@@ -44,11 +46,15 @@ def send_s3(filepath,token,production=False):
4446
, ('file', infile ))
4547

4648
c = session()
47-
response = c.post(url,files=form, headers=s3headers)
49+
response = c.post(url,files=form, headers=s3headers,auth=auth)
50+
print(response)
4851
if(response.text):
4952
raise Exception(response.text)
5053

51-
response = c.get(chkurl+'/'+bucket+'/'+key,headers=headers)
54+
print(chkurl+'/'+bucket+'/'+key+'/')
55+
print(headers)
56+
response = c.get(chkurl+'/'+bucket+'/'+key+'/',headers=headers,auth=auth)
57+
print(response)
5258
md5 = response.json()["md5"]
5359
filename = filepath.split('/')[-1]
5460

@@ -58,7 +64,7 @@ def send_s3(filepath,token,production=False):
5864

5965
return(fileinfo)
6066

61-
def caltechdata_write(metadata,token,files=[],production=False):
67+
def caltechdata_write(metadata,token,files=[],production=False,auth=None):
6268

6369
#If files is a string - change to single value array
6470
if isinstance(files, str) == True:
@@ -67,7 +73,7 @@ def caltechdata_write(metadata,token,files=[],production=False):
6773
fileinfo=[]
6874

6975
for f in files:
70-
fileinfo.append(send_s3(f, token, production))
76+
fileinfo.append(send_s3(f, token, production,auth))
7177

7278
if production == True:
7379
url = "https://data.caltech.edu/submit/api/create/"
@@ -89,5 +95,5 @@ def caltechdata_write(metadata,token,files=[],production=False):
8995
dat = json.dumps({'record': newdata})
9096

9197
c = session()
92-
response = c.post(url,headers=headers,data=dat)
98+
response = c.post(url,headers=headers,data=dat,auth=auth)
9399
return response.text

0 commit comments

Comments
 (0)