주어진 핸들을 가진 항목이 DSpace에 있는지 확인하기 위해 DSpace 5.5 API에 get 요청을 보내려고합니다.
브라우저에서 테스트했을 때 제대로 작동했습니다 (리턴 코드 200, 검색된 항목에 대한 데이터가 있습니다).
그런 다음 Python 콘솔에서 Python 3 요청 모듈로 요청 보내기 테스트를 시작했습니다. 다시, DSpace API는 응답에서 올바른 응답 코드 (200)와 json 데이터를 반환했습니다.
그래서 테스트 된 함수를 스크립트에 구현했고 갑자기 DSpace API가 오류 코드 500을 반환하기 시작했습니다. DSpace 로그에서 다음 오류 메시지를 가로 질러 왔습니다.
org.dspace.rest.RestIndex @ REST Login Success for user: [email protected]
2017-01-03 15:38:34,326 ERROR org.dspace.rest.Resource @ Something get wrong. Aborting context in finally statement.
2017-01-03 15:38:34,474 ERROR org.dspace.rest.Resource @ Something get wrong. Aborting context in finally statement.
2017-01-03 15 : 38 : 34,598 오류 org.dspace.rest.Resource @ 뭔가 잘못되었습니다. finally 문에서 컨텍스트를 중단합니다.
DSpace 문서에 따르면 요청은 다음과 같이해야합니다.
GET /handle/{handle-prefix}/{handle-suffix}
DSpace 서버에서 API 끝점을 처리하도록 가리 키므로 전체 요청을 전송해야합니다 https://dspace.cuni.cz/rest/handle/123456789/937
(직접 테스트 할 수 있다고 생각합니다).
브라우저에서 다음과 같은 응답을받습니다.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<item>
<expand>metadata</expand
<expand>parentCollection</expand>
<expand>parentCollectionList</expand>
<expand>parentCommunityList</expand>
<expand>bitstreams</expand>
<expand>all</expand>
<handle>123456789/937</handle>
<id>1423</id>
<name>Komparace vývoje české a slovenské pravicové politiky od roku 1989 do současnosti</name>
<type>item</type>
<archived>true</archived>
<lastModified>2016-12-20 17:52:30.641</lastModified
<withdrawn>false</withdrawn>
</item>
Python 콘솔에서 테스트 할 때 내 코드는 다음과 같습니다.
from urllib.parse import urljoin
import requests
def document_in_dspace(handle):
url = 'https://dspace.cuni.cz/rest/handle/'
r_url = urljoin(url, handle)
print(r_url)
r = requests.get(r_url)
if r.status_code == requests.codes.ok:
print(r.text)
print(r.reason)
return True
else:
print(r.reason)
print(r.text)
return False
를 사용하여 Python 콘솔에서이 함수를 호출 한 후 document_in_dspace('123456789/937')
응답은 다음과 같습니다.
https://dspace.cuni.cz/rest/handle/123456789/937
{"id":1423,"name":"Komparace vývoje české a slovenské pravicové politiky od roku 1989 do současnosti","handle":"123456789/937","type":"item","link":"/rest/items/1423","expand":["metadata","parentCollection","parentCollectionList","parentCommunityList","bitstreams","all"],"lastModified":"2016-12-20 17:52:30.641","parentCollection":null,"parentCollectionList":null,"parentCommunityList":null,"bitstreams":null,"archived":"true","withdrawn":"false"}
OK
True
그래서이 함수를 내 스크립트에 구현하기로 결정했지만 (변경없이) 이제 DSpace API는 함수가 호출 될 때 응답 코드 500을 반환합니다.
구현에 대한 세부 정보는 다음과 같습니다.
def get_workflow_process(document):
if document.document_in_dspace(handle=document.handle) is True:
return 'delete'
else:
return None
wf_process = get_workflow_process(document)
log.msg("Document:", document.doc_id, "Workflow process:", wf_process)
출력은 다음과 같습니다.
2017-01-04 11:08:45+0100 [-] DSPACE API response code: 500
2017-01-04 11:08:45+0100 [-] Internal Server Error
2017-01-04 11:08:45+0100 [-]
2017-01-04 11:08:45+0100 [-] False
2017-01-04 11:08:45+0100 [-] Document: 28243 Workflow process: None
문제의 원인과 해결 방법을 제안 해 주시겠습니까? 나는 이것이 파이썬 콘솔에서 작동하지만 실제 스크립트에서는 작동하지 않는다는 사실에 상당히 놀랐고 내가 스스로 알아낼 수없는 것 같습니다. 감사합니다!
나는 그것을 알아 낸 것 같다. 문제는 아마도 함수 의 handle
매개 변수에있는 일부 후행 개행 문자에 document_in_dspace
있었습니다. 업데이트 된 기능은 다음과 같습니다.
def document_in_dspace(handle):
url = 'https://dspace.cuni.cz/rest/handle/' # TODO: Move to config
hdl = handle.rstrip()
prefix, suffix = str(hdl).split(sep='/')
r_url = url + prefix + '/' + suffix
log.msg("DSpace API request url is:", r_url)
r = requests.get(r_url, timeout=1)
if r.status_code == requests.codes.ok:
log.msg("DSPACE API response code:", r.status_code)
log.msg("Document with handle", handle, "found in DSpace!")
log.msg("Document handle:", handle)
log.msg("Request:\n", r.request.headers)
log.msg("\n")
log.msg(r.reason)
return True
else:
log.msg("DSPACE API response code:", r.status_code)
log.msg("Document with handle", handle, "not found in DSpace!")
log.msg("Document handle:", handle)
log.msg("Request:\n", r.request.headers)
log.msg("\n")
log.msg(r.reason)
return False
기본적으로 내가 한 일은 .rstrip()
원치 않는 모든 후행 문자를 제거하기 위해 핸들 문자열 을 호출 한 다음 핸들의 prefix
및 suffix
부분 (확실 함을 위해)을 분리하고 r_url
모든 부분을 함께 결합하여 요청 URL ( )을 구성했습니다. .
앞으로 기능을 더 예쁘게 만들 겠지만 적어도 지금은 의도 한대로 작동합니다.
출력은 다음과 같습니다.
2017-01-04 15:06:16+0100 [-] Checking if document with handle 123456789/937
is in DSpace...
2017-01-04 15:06:16+0100 [-] DSpace API request url is: https://dspace.cuni.cz/rest/handle/123456789/937
2017-01-04 15:06:16+0100 [-] DSPACE API response code: 200
2017-01-04 15:06:16+0100 [-] Document with handle 123456789/937
found in DSpace!
2017-01-04 15:06:16+0100 [-] Document handle: 123456789/937
2017-01-04 15:06:16+0100 [-] Request:
{'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'python-requests/2.11.1', 'Connection': 'keep-alive', 'Accept': '*/*'}
2017-01-04 15:06:16+0100 [-]
2017-01-04 15:06:16+0100 [-] OK
그럼에도 불구하고 DSpace API는 응답 코드 404 대신 주어진 핸들이있는 항목이 저장소에 없을 때 응답 코드 500을 반환하는 것처럼 보입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다