This repository has been archived by the owner on Aug 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
28-ArchivesSpace-API-Workshop.html
58 lines (49 loc) · 1.97 KB
/
28-ArchivesSpace-API-Workshop.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html>
<head>
<link href="css/slides.css" rel="stylesheet" />
</head>
<body>
<nav>
<a id="start-slide" rel="nav" href="00-ArchivesSpace-API-Workshop.html" title="Return to start of presentation">Start</a>
<a id="prev-slide" rel="nav" href="27-ArchivesSpace-API-Workshop.html" title="Previous slide">Prev</a>
<a id="next-slide" rel="nav" href="29-ArchivesSpace-API-Workshop.html" title="Next slide">Next</a>
</nav>
<section><h1>3. Authentication</h1>
<h2>Send our username and password</h2>
<h3>Putting it all together</h3>
<p>Open the IDLE text editor and create a new file
called <strong>login.py</strong>.</p>
<p>We’ll create a python function and add prompts for api url,
username and password to test it. Note the additional <em>urllib</em> modules
imported.</p>
<pre><code class="language-python"> #!/usr/bin/env python3
import urllib.request
import urllib.parse
import urllib.error
def login (api_url, username, password):
'''This function logs into the ArchivesSpace REST API and shows the text response'''
data = urllib.parse.urlencode({'password': password})
data = data.encode('utf-8')
req = urllib.request.Request(
url = api_url+'/users/'+username+'/login',
data = data)
response = urllib.request.urlopen(req)
status = response.getcode()
print('HTTP status code', status)
return response.read().decode('UTF-8')
if __name__ == '__main__':
import getpass
api_url = input('ArchivesSpace API URL: ')
username = input('ArchivesSpace username: ')
password = getpass.getpass('ArchivesSpacew password: ')
print('Logging in', api_url)
s = login(api_url, username, password)
print(s)
print('Success!')
</code></pre>
<p>Now “Run” the python script and review the results like we did before.</p>
</section>
<script type="text/javascript" src="js/keyboard-nav.js"></script>
</body>
</html>