This repository has been archived by the owner on Mar 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
python client: switch to requests library (closes #308)
- Loading branch information
1 parent
0745e85
commit b4c95be
Showing
7 changed files
with
60 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
import httplib2, sys, base64 | ||
import requests, sys | ||
|
||
endpoint = 'https://mds.datacite.org/metadata' | ||
#endpoint = 'https://mds.datacite.org/metadata' | ||
endpoint = 'https://mds.test.datacite.org/metadata' | ||
|
||
if (len(sys.argv) < 4): | ||
raise Exception('Please provide username, password and doi') | ||
|
||
h = httplib2.Http() | ||
auth_string = base64.encodestring(sys.argv[1] + ':' + sys.argv[2]) | ||
response, content = h.request(endpoint + '/' + sys.argv[3], | ||
'DELETE', | ||
headers={'Authorization':'Basic ' + auth_string}) | ||
username, password, doi = sys.argv[1:] | ||
|
||
if (response.status != 201): | ||
print str(response.status) | ||
print(content.decode('utf-8')) | ||
response = requests.delete(endpoint + '/' + doi, | ||
auth = (username, password)) | ||
|
||
print str(response.status_code) + " " + response.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import requests, sys | ||
|
||
#endpoint = 'https://mds.datacite.org/doi' | ||
endpoint = 'https://mds.test.datacite.org/doi' | ||
|
||
if (len(sys.argv) < 4): | ||
raise Exception('Please provide username, password and doi') | ||
|
||
username, password, doi = sys.argv[1:] | ||
|
||
response = requests.get(endpoint + '/' + doi, | ||
auth = (username, password)) | ||
|
||
if (response.status_code != 200): | ||
print str(response.status_code) + " " + response.text | ||
else: | ||
print response.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import httplib2, sys, base64 | ||
import requests, sys | ||
|
||
endpoint = 'https://mds.datacite.org/metadata' | ||
#endpoint = 'https://mds.datacite.org/metadata' | ||
endpoint = 'https://mds.test.datacite.org/metadata' | ||
|
||
if (len(sys.argv) < 4): | ||
raise Exception('Please provide username, password and doi') | ||
|
||
h = httplib2.Http() | ||
auth_string = base64.encodestring(sys.argv[1] + ':' + sys.argv[2]) | ||
response, content = h.request(endpoint + '/' + sys.argv[3], | ||
headers={'Accept':'application/xml', | ||
'Authorization':'Basic ' + auth_string}) | ||
username, password, doi = sys.argv[1:] | ||
|
||
if (response.status != 200): | ||
print str(response.status) | ||
|
||
print(content.decode('utf-8')) | ||
response = requests.get(endpoint + '/' + doi, | ||
auth = (username, password), | ||
headers = {'Accept':'application/xml'}) | ||
|
||
if (response.status_code != 200): | ||
print str(response.status_code) + " " + response.text | ||
else: | ||
print response.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,18 @@ | ||
import httplib2, sys, base64, codecs | ||
import requests, sys, codecs | ||
|
||
#endpoint = 'https://mds.datacite.org/doi' | ||
endpoint = 'https://mds.test.datacite.org/doi' | ||
|
||
if (len(sys.argv) < 4): | ||
raise Exception('Please provide username, password, location of doi-url file') | ||
|
||
endpoint = 'https://mds.datacite.org/doi' | ||
|
||
body_unicode = codecs.open(sys.argv[3], 'r', encoding='utf-8').read().strip() | ||
username, password, filename = sys.argv[1:] | ||
|
||
print(body_unicode); | ||
file = codecs.open(sys.argv[3], 'r', encoding='utf-8').read().strip() | ||
|
||
h = httplib2.Http() | ||
auth_string = base64.encodestring(sys.argv[1] + ':' + sys.argv[2]) | ||
response = requests.post(endpoint, | ||
auth = (username, password), | ||
data = file.encode('utf-8'), | ||
headers = {'Content-Type':'text/plain;charset=UTF-8'}) | ||
|
||
response, content = h.request(endpoint, | ||
'POST', | ||
body = body_unicode.encode('utf-8'), | ||
headers={'Content-Type':'text/plain;charset=UTF-8', | ||
'Authorization':'Basic ' + auth_string}) | ||
if (response.status != 201): | ||
print str(response.status) | ||
|
||
print(content.decode('utf-8')) | ||
print str(response.status_code) + " " + response.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
import httplib2, sys, base64, codecs | ||
import requests, sys, codecs | ||
|
||
#endpoint = 'https://mds.datacite.org/metadata' | ||
endpoint = 'https://mds.test.datacite.org/metadata' | ||
|
||
if (len(sys.argv) < 4): | ||
raise Exception('Please provide username, password and location of metadata file') | ||
|
||
endpoint = 'https://mds.datacite.org/metadata' | ||
|
||
body_unicode = codecs.open(sys.argv[3], 'r', encoding='utf-8').read() | ||
username, password, filename = sys.argv[1:] | ||
|
||
print(body_unicode); | ||
metadata = codecs.open(filename, 'r', encoding='utf-8').read() | ||
|
||
h = httplib2.Http() | ||
auth_string = base64.encodestring(sys.argv[1] + ':' + sys.argv[2]) | ||
response, content = h.request(endpoint, | ||
'POST', | ||
body = body_unicode.encode('utf-8'), | ||
headers={'Content-Type':'application/xml;charset=UTF-8', | ||
'Authorization':'Basic ' + auth_string}) | ||
if (response.status != 201): | ||
print str(response.status) | ||
|
||
print(content.decode('utf-8')) | ||
response = requests.post(endpoint, | ||
auth = (username, password), | ||
data = metadata.encode('utf-8'), | ||
headers = {'Content-Type':'application/xml;charset=UTF-8'}) | ||
|
||
print str(response.status_code) + " " + response.text |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.