Skip to content
Snippets Groups Projects
Commit ad48985b authored by bastien's avatar bastien
Browse files

add test TEI files to SWORD API + fix some stuff

parent 3709ad9e
No related branches found
No related tags found
No related merge requests found
...@@ -300,7 +300,8 @@ def createXml_sendHal(numero,listauthors, lang_title, title_publi, name_conf, nb ...@@ -300,7 +300,8 @@ def createXml_sendHal(numero,listauthors, lang_title, title_publi, name_conf, nb
@shared_task @shared_task
def sendselect_2hal(name_user, login_user,id_hal_user,mail_reponse,labo_auth_final,listdomains,login_depot,passwd_depot,choice_depot,list_publis_to_update,csvfile): def sendselect_2hal(name_user, login_user,id_hal_user,mail_reponse,labo_auth_final,listdomains,login_depot,passwd_depot,choice_depot,list_publis_to_update,csvfile):
print("list_publis_to_update")
print(list_publis_to_update)
mail_message = "Bonjour\n\nSuite à votre demande sur l'appli Haltools, veuillez trouver ci-dessous les résultats de dépôts.\n\n" mail_message = "Bonjour\n\nSuite à votre demande sur l'appli Haltools, veuillez trouver ci-dessous les résultats de dépôts.\n\n"
with open('bibtex_csv_files/'+csvfile+'.csv', 'r', newline='', encoding='utf-8') as csv_file : with open('bibtex_csv_files/'+csvfile+'.csv', 'r', newline='', encoding='utf-8') as csv_file :
csvr = csv.reader(csv_file, delimiter =',') csvr = csv.reader(csv_file, delimiter =',')
......
from django.core.management.base import BaseCommand, CommandError
from haltools.settings import BASE_DIR
import requests
class Command(BaseCommand):
help = "Test sending file TEI to HAL through Sword API, just fill some variables to test"
def handle(self, *args, **options):
print("begin")
errormsg = ''
requ_msg = ''
login_user = 'bdoreau'
id_hal_user = 'bastien-doreau'
login_depot = 'bdoreau'
passwd_depot = '******'
namefile = BASE_DIR+"/xml_files/bdoreauCI1.xml"
data = open(namefile)
# HEADERS request
headers = {
'Packaging': 'http://purl.org/net/sword-types/AOfr',
'Content-Type': 'text/xml',
'On-Behalf-Of': 'login|'+login_user+';idhal|'+id_hal_user,
}
try :
response = requests.post('https://api-preprod.archives-ouvertes.fr/sword/hal/', headers=headers, data=data, auth=(login_depot, passwd_depot),timeout=60)
except requests.exceptions.RequestException as e:
print ("ERROR REQUEST {0}".format(e))
requ_msg += "ERROR REQUEST : {0} -- ".format(e)
except requests.exceptions.Timeout as t :
print ("ERROR TIMEOUT REQUEST {0}".format(t))
requ_msg += "ERROR TIMEOUT : {0} -- ".format(t)
print("response POST : code {0}".format(response.status_code))
print("response POST : text {0}".format(response.text))
code_http = response.status_code
if (code_http != 200) and (code_http != 202) :
requ_msg += "RESPONSE : {0}".format(response.text)
else :
requ_msg += "RESPONSE : OK {0}".format(errormsg)
return None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment