919.459.6097 info@reso.org  

Python Connection Example

"""
  Basic connection code, works on virtually all MLS's that don't require a specific user-agent
"""
import librets

class rets_connection:
"""
  simple static object to keep all our credentials in one spot, for production code this might be a wrapper for a DB 
  or config file.
"""
   user_id = "Joe"
   passwd = "Schmoe"
   login_url = "http://demo.crt.realtors.org:6103/rets/login"
      


try:
   session = librets.RetsSession(rets_connection.login_url)
   #At this point you're connected to the Rets server, but not authenticated so not even worth checking for success
   #If you need to change user-agent (Rapattoni servers)
   #session.SetUserAgent("myAgentCode/1.5")
   if (not session.Login(rets_connection.user_id, rets_connection.passwd)):
       #
       sys.exit(2)
   metadata = session.GetMetadata()
   systemdata = metadata.GetSystem()
   for attribute in systemdata.GetAttributeNames():
         print attribute, systemdata.GetStringAttribute(attribute)

   session.Logout()
except Exception, e:
   print "Exception: ", e
DLU March 16th, 2016