<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://textserver.lsi.upc.edu/wiki/index.php?action=history&amp;feed=atom&amp;title=Python2_Interactive_Client</id>
		<title>Python2 Interactive Client - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://textserver.lsi.upc.edu/wiki/index.php?action=history&amp;feed=atom&amp;title=Python2_Interactive_Client"/>
		<link rel="alternate" type="text/html" href="http://textserver.lsi.upc.edu/wiki/index.php?title=Python2_Interactive_Client&amp;action=history"/>
		<updated>2026-05-09T03:27:32Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://textserver.lsi.upc.edu/wiki/index.php?title=Python2_Interactive_Client&amp;diff=150&amp;oldid=prev</id>
		<title>Padro: Created page with &quot;&lt;syntaxhighlight lang=&quot;python&quot; line=&quot;1&quot; &gt; #! /usr/bin/python  ######################################################################## # #  Example client to submit an interac...&quot;</title>
		<link rel="alternate" type="text/html" href="http://textserver.lsi.upc.edu/wiki/index.php?title=Python2_Interactive_Client&amp;diff=150&amp;oldid=prev"/>
				<updated>2018-08-24T08:53:20Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line=&amp;quot;1&amp;quot; &amp;gt; #! /usr/bin/python  ######################################################################## # #  Example client to submit an interac...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line=&amp;quot;1&amp;quot; &amp;gt;&lt;br /&gt;
#! /usr/bin/python&lt;br /&gt;
&lt;br /&gt;
########################################################################&lt;br /&gt;
#&lt;br /&gt;
#  Example client to submit an interactive request to TextServer &lt;br /&gt;
# SERVICENAME service. &lt;br /&gt;
#  Input may be a plain text or a text file.  No ZIP files.&lt;br /&gt;
#  Output will be in the requested format (XML, json, conll)&lt;br /&gt;
#&lt;br /&gt;
########################################################################&lt;br /&gt;
&lt;br /&gt;
# import required libraries&lt;br /&gt;
import urllib2&lt;br /&gt;
# You may need to install &amp;quot;poster&amp;quot; python module for these two:&lt;br /&gt;
from poster.encode import multipart_encode&lt;br /&gt;
from poster.streaminghttp import register_openers&lt;br /&gt;
&lt;br /&gt;
# Register the streaming http handlers with urllib2&lt;br /&gt;
register_openers()&lt;br /&gt;
&lt;br /&gt;
# set query elements&lt;br /&gt;
text = raw_input('Text to analyze: ')&lt;br /&gt;
lang = raw_input('Language: ')&lt;br /&gt;
out = raw_input('Output format (xml,json,conll,naf): ')&lt;br /&gt;
user = raw_input('TextServer Username: ')&lt;br /&gt;
pwd = raw_input('TextServer Password: ')&lt;br /&gt;
&lt;br /&gt;
# Encode query in a form-data.&lt;br /&gt;
# 'headers' contains the necessary Content-Type and Content-Length.&lt;br /&gt;
# 'datagen' is a generator object that yields the encoded parameters.&lt;br /&gt;
datagen, headers = multipart_encode({'username':user,&lt;br /&gt;
                                     'password':pwd,&lt;br /&gt;
                                     'text_input':text,&lt;br /&gt;
                                     'language':lang,&lt;br /&gt;
                                     'output':out,&lt;br /&gt;
                                     'interactive':'1'&lt;br /&gt;
                                     } )&lt;br /&gt;
# service URL&lt;br /&gt;
service = &amp;quot;SERVICENAME&amp;quot;&lt;br /&gt;
url = &amp;quot;http://frodo.lsi.upc.edu:8080/TextWS/textservlet/ws/processQuery/&amp;quot;+service&lt;br /&gt;
&lt;br /&gt;
# Create the Request object&lt;br /&gt;
request = urllib2.Request(url, datagen, headers)&lt;br /&gt;
try:&lt;br /&gt;
  # Actually do the request, and get the response&lt;br /&gt;
  resp =  urllib2.urlopen(request).read()&lt;br /&gt;
&lt;br /&gt;
except urllib2.HTTPError, e:&lt;br /&gt;
  # handle connection errors&lt;br /&gt;
  print e, &amp;quot;-&amp;quot;, e.read()&lt;br /&gt;
  exit()&lt;br /&gt;
&lt;br /&gt;
# No error, appropriately process response&lt;br /&gt;
# (e.g. parsing XML or JSON, and doing clever stuff with the content)&lt;br /&gt;
print resp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Padro</name></author>	</entry>

	</feed>