0

How do I get the port no on the server (on which web2py app is deployed) from inside the web2py application (for ex. controller or module)?

I am using urllib to interact with another action inside the controller by doing this

response = urllib2.urlopen('http://127.0.0.1:8000%s?%s'%(URL('unregister_relationship.json'),urllib.urlencode(data))) 
response = json.loads(response.read())

but this needs port no to be known beforehand, I want it to be dynamic.

1 Answers1

0

The URL() helper takes scheme and host arguments to generate an absolute URL. Also, no need to use urllib.urlencode to generate the query string, as you can pass a dictionary as the vars argument:

urllib2.urlopen(URL('unregister_relationship.json', vars=data, scheme='http', host=True))

As an alternative, you might also consider using JSON-RPC to allow the two apps to communicate.

Anthony
  • 25,466
  • 3
  • 28
  • 57