Sunday 27 October 2013

How to use web-services in pygtk for desktop application



Suds is a one Lightweight SOAP client module which is used for web services.  We send web request to server by the help of suds, this request will go to server and server will return response in format.


From my perspective I have used suds for desktop application login.  I am using 1 desktop application and I want to login in it with server. Then by suds module it will send login request to server with username password and server will return response-“this username and password are correct or wrong”.


So we can say that with the help of suds module, we can send request to server and get response for any task. It is nothing but web services.

How to use suds


First download suds Lightweight SOAP client module from here--DOWNLOAD  and if you want to read more about suds then go through URL


import suds.metrics as metrics
from suds import WebFault
from suds.client import Client


uid = username
pwd = password
url = 'http://www.thomas-bayer.com/axis2/services/BLZService?wsdl'

client = Client(url) 
print client
data = client.service.Dologin(uid,pwd)
print 'token="%s"' % data



data  will print server response.
If u print client then it will show below result

Suds - version: 0.3.3 build: (beta) R397-20081121

Service (WebServiceTestBeanService) 
tns="http://www.thomas-bayer.com/axis2/services/BLZService?wsdl'
   Prefixes (1):
     ns0 = "http://www.thomas-bayer.com/axis2/services/BLZService?wsdl'   Ports (1):
     (Soap)
       Methods:
         addPerson(Person person, )
         echo(xs:string arg0, )
         getList(xs:string str, xs:int length, )
         getPercentBodyFat(xs:string name, xs:int height, xs:int weight)
         getPersonByName(Name name, )
         hello()
         testExceptions()
         testListArg(xs:string[] list, )
         testVoid()
         updatePerson(AnotherPerson person, name name, )
   Types (23):
     Person
     Name
     Phone
     AnotherPerson

Or second method
 
import urllib2
baseurl = 'http://localhost:7080/'
username = 'myuser'
password = 'mypassword'
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, baseurl, username, password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)

Or 

import urllib
import urllib2

url = 'http://example.com/...'
values = { 'productslug': 'bar','qty': 'bar' }
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
result = response.read()
print result
 
If you guys need any help, then comment below. I will support you.
Thanks

No comments:

Post a Comment