Difference between revisions of "Python3 Batch Client"
From Textserver wiki
(Created page with "<syntaxhighlight lang="python" line="1" > #!/usr/bin/env python3 import requests import xml.etree.ElementTree # set query elements fname = raw_input('Input ZIP file: ') lang...") |
|||
Line 34: | Line 34: | ||
dom = xml.etree.ElementTree.XML(resp) | dom = xml.etree.ElementTree.XML(resp) | ||
tkid = dom.text | tkid = dom.text | ||
− | print "Job sumbitted. Token id=",tkid | + | print ("Job sumbitted. Token id=",tkid) |
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 10:33, 24 August 2018
1 #!/usr/bin/env python3
2
3 import requests
4 import xml.etree.ElementTree
5
6 # set query elements
7 fname = raw_input('Input ZIP file: ')
8 lang = raw_input('Language: ')
9 out = raw_input('Output format (xml,json,conll,naf): ')
10 user = raw_input('TextServer Username: ')
11 pwd = raw_input('TextServer Password: ')
12
13 # Create request
14 request_data = {'username' : user
15 'password' : pwd,
16 'file' : open(fname,"rb"),
17 'language': lang,
18 'output': out,
19 'interactive' : '0' }
20
21 # service URL
22 service = "SERVICENAME"
23 url = "http://frodo.lsi.upc.edu:8080/TextWS/textservlet/ws/processQuery/"+service
24
25 # Send request and get response
26 resp = requests.post(url, files=request_data)
27
28 # HTTP error, raise exception
29 if resp.status_code != requests.codes.ok :
30 resp.raise_for_status()
31
32 # No error. Server response should include a job tokenID, retrieve it
33 dom = xml.etree.ElementTree.XML(resp)
34 tkid = dom.text
35 print ("Job sumbitted. Token id=",tkid)