I'm new to XMLRPC but I need to use it (xmlrpclib in Python 2.7) to communicate with a server (www.neos-server.org) which accepts xml files. I'm behind a firewall that severely restricts outgoing and incoming traffic, but I'm able to browse the web mostly unimpeded using a webproxy.
Test 1 and 2 (below) work, but Test 3 results in an HTTP 502 error (cantconnect)
import urllib2
import xmlrpclib
import httplib
class ProxyTransport(xmlrpclib.Transport):
def request(self, host, handler, request_body, verbose):
self.verbose = verbose
url = 'http://' + host + handler
if self.verbose: "ProxyTransport URL: [%s]" % url
request = urllib2.Request(url)
request.add_data(request_body)
request.add_header("User-Agent", self.user_agent)
request.add_header("Content-Type", "text/xml")
proxy_handler = urllib2.ProxyHandler({"http":"MYPROXY:8080"})
opener = urllib2.build_opener(proxy_handler)
f = opener.open(request)
return(self.parse_response(f))
# TEST 1 - HTML fetching
def test1():
html = urllib2.urlopen("http://www.google.com").read() # note no proxy setup here
print html
# TEST 2 - XMLRPC sample server fetching
def test2():
p = ProxyTransport()
test_url = "http://betty.userland.com"
#test_server = xmlrpclib.Server(test_url) # gives <ProtocolError for betty.userland.com/RPC2: 403 WebTrap>
test_server = xmlrpclib.Server(test_url, transport=p)
test_api = "examples.getStateName(9)"
print "API: %s" % test_api
r = eval("test_server.%s" % test_api)
print "Result: ", r
# TEST 3 - XMLRPC server (NEOS)
def test3():
# Setup proxy and server
p = ProxyTransport()
NEOS_HOST = "www.neos-server.org"
NEOS_PORT = 3332
neos = xmlrpclib.Server("http://%s:%d" % (NEOS_HOST, NEOS_PORT), transport = p)
# Talk
print "Ping Neos..."
neos.ping()
test1()
test2()
test3()
I've tried a couple different solutions (https://gist.github.com/nathforge/980961, https://mail.python.org/pipermail/python-list/2006-July/367049.html) but they don't seem to work. I assume I need to be able to ping before I can send/receive xml files and results. What should I try next?