×

Discussion Board

Results 1 to 3 of 3

Hybrid View

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    21

    REST API call inside python script

    hello!
    is it or how is it possible to use the REST API inside a python script, which is running on the MWS?
    for example i want to call https://domain_name.mymobilesite.net...sence/location and process the returned XML data in the python script.
    Code:
    import urlib
    content = urllib.urlopen("https://domain_name.mymobilesite.net/rest/presence/availability").read()
    this code leads to the point where the phone (n95 8gb) asks for accesspoints, so it doesn´t use the already established internet connection of the MWS! an unusable behavior! any hints or other approaches to access the REST API?
    THX for help!
    Askin
    Last edited by _Askin_; 2009-03-03 at 00:59.

  2. #2
    Registered User
    Join Date
    Dec 2003
    Posts
    20

    Re: REST API call inside python script

    Hello.

    I stumbled to that one too once. My ugly solution was to define the access point manually in the script (works then only on that phone if IAPs are not changed, not good as I said).

    Code:
    iap = socket.access_point(7)                    # WARNING: Hard coded IAP!!
    socket.set_default_access_point(iap)
    response = urllib.urlopen("http://web.address.net").read()
    iap.stop()
    The IAP number 7 in the example must be replaced to suite your needs. Use PyS60 socket module function access_points (lists access points id's and names that are available) to determine which one to use.

    If someone knows more, please suggest a better way! ;-)

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    31

    Re: REST API call inside python script

    I tried a simple sample but i have an error with import xml.sax, the error is "no module name xml.sax" i think its because i need pyexpat from pyxml but i don´t find it on the web.

    Is there another way to do this sample whitout the module xml.sax?
    my sample code:

    Code:
    import appuifw
    import e32
    import urllib
    import xml.sax
    import xml.sax.handler
    
    
    
    class DeviceStateHandler(xml.sax.handler.ContentHandler):
    	
    	def __init__(self, device):
    		self.device = device
    	
    	
    	def startElement(self, name, attributes):
    		if name == "devicestate":
    			self.device = DeviceState(attributes["battery_level"],attributes["localtime"], attributes["connection_type"])
    			
    
    
    
    class DeviceState:
    	
    	def __init__(self, battery_level, localtime, connection_type):
    		self.battery_level = battery_level
    		self.localtime = localtime
    		self.connection_type = connection_type
    	
    	
    	def getAttributes(self):
    		return u'Battery Level: ' + self.battery_level + u'\nLocalTime: ' + self.localtime + u'\nConnection Type: ' + self.connection_type
    
    
    
    def quit():
    	appuifw.app.set_exit() 
    
    
    
    appuifw.app.exit_key_handler = quit
    
    
    
    def print(text):
    		appuifw.note(text, 'info')
    
    
    
    def stateDevice():
    	url = "http://127.0.0.1/rest/presence/devicestate"
    	content = urllib.urlopen(url).read()
    	
    	handler = DeviceStateHandler()
    	xml.sax.parseString(content, handler)
    	
    	print(handler.device.getAttributes())
    
    
    
    appuifw.app.menu = [(u'State', stateDevice)]
    
    
    
    appuifw.app.title = u'Sample REST Services'
    
    
    
    app_lock = e32.Ao_lock() 
    
    
    
    app_lock.wait()
    Thanks for help!!

Similar Threads

  1. [moved] signed python script shell
    By joemarshall in forum Symbian
    Replies: 18
    Last Post: 2009-03-06, 03:17
  2. Call audio control (SDK plugin API) findings summary
    By aymen@telepo.com in forum Symbian
    Replies: 0
    Last Post: 2009-02-19, 07:51
  3. PC Suite error: (Code: Init IMediaControl2) HELP?!
    By chunkyspudmonkey in forum General Development Questions
    Replies: 29
    Last Post: 2008-06-30, 11:47
  4. Hang up and Dial a call from inside application
    By skhimsara in forum Symbian
    Replies: 0
    Last Post: 2006-03-13, 06:13
  5. Put Call On hold Using ETel API
    By sailaja_v_s in forum Symbian
    Replies: 0
    Last Post: 2003-08-16, 21:57

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×