Skip to content

Commit 811ed20

Browse files
committed
Fix error message
1 parent beaddf2 commit 811ed20

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

caltechdata_api/get_metadata.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
from datacite import DataCiteMDSClient, schema40
44
from caltechdata_api import decustomize_schema
55

6-
def get_metadata(idv,production=True):
6+
def get_metadata(idv,production=True,auth=None):
77
# Returns just DataCite metadata
88

99
if production==True:
1010
api_url = "https://data.caltech.edu/api/record/"
1111
else:
1212
api_url = "https://cd-sandbox.tind.io/api/record/"
1313

14-
r = requests.get(api_url+str(idv))
14+
r = requests.get(api_url+str(idv),auth=auth)
1515
r_data = r.json()
1616
if 'message' in r_data:
17-
raise AssertionError('id '+idv+' expected http status 200, got '+r_data.status+r_data.message)
17+
raise AssertionError('id '+str(idv)+' expected http status 200, got '\
18+
+str(r.status_code)+' '+r_data['message'])
1819
if not 'metadata' in r_data:
1920
raise AssertionError('expected as metadata property in response, got '+r_data)
2021
metadata = r_data['metadata']
@@ -39,14 +40,18 @@ def get_metadata(idv,production=True):
3940
help='The CaltechDATA ID for each record of interest')
4041
parser.add_argument('-test',dest='production', action='store_false')
4142
parser.add_argument('-xml',dest='save_xml', action='store_true')
43+
parser.add_argument('-auth_user',help='Username for basic authentication')
44+
parser.add_argument('-auth_pass',help='Password for basic authentication')
4245

4346
args = parser.parse_args()
4447

48+
production = args.production
49+
auth = None
50+
if args.auth_user != None:
51+
auth = (args.auth_user,args.auth_pass)
52+
4553
for idv in args.ids:
46-
if args.production == False:
47-
metadata = get_metadata(idv,args.production)
48-
else:
49-
metadata = get_metadata(idv)
54+
metadata = get_metadata(idv,production,auth)
5055
outfile = open(str(idv)+'.json','w')
5156
outfile.write(json.dumps(metadata))
5257
outfile.close()

0 commit comments

Comments
 (0)