使用Python访问Highrise的API?

时间:2010-11-01 16:24:29

标签: python highrise

如何使用Python访问37个Highrise的API信号?找到PHP / Ruby的包装器,但不是Python。我现在正在写自己的,有人建议用Python来克服第一道认证的障碍吗?

4 个答案:

答案 0 :(得分:4)

我写了(我写的,真的)一个用于Python的Highrise API包装器。它为每个Highrise类使用Python对象,并且像Django ORM一样工作:

>>> from pyrise import *
>>> Highrise.server('my-server')
>>> Highrise.auth('api-key-goes-here')
>>> p = Person()
>>> p.first_name = 'Joe'
>>> p.last_name = 'Schmoe'
>>> p.save()

您可以从GitHub获取来源:https://github.com/feedmagnet/pyrise

或者从PyPI安装它:

$ sudo pip install pyrise

答案 1 :(得分:1)

当我偶然发现你的问题时,我正在解决这个问题。到目前为止,这是我一起入侵的内容。它不漂亮(但)它的工作原理。我不知道Pycurl,看了一会儿后我又回到了urllib2。 Highrise使用基本身份验证,因此您不必使用CURL就可以使用urllib2。您只需要完成所有Pword Manager步骤。输出是所有公司或人员的长XML文件,具体取决于您插入的URL。如果你只想要一个人就可以做'http ...... / people / 123.xml'或'http ...... / people / 123-fname-lname.xml'(就像你看到的那样)当您实际上在高层建筑中添加了.xml时,在网址中。

import ullib2    

PEOPLEurl = 'http://yourcompany.highrisehq.com/people.xml' #get all the people
# or 
COMPANYurl = 'http://yourcompany.highrisehq.com/company.xml' #get all companies

token = '12345abcd' #your token
password = 'X'

passmanager = urllib2.HTTPPasswordMgrWithDefaultRealm()
passmanager.add_password(None, PEOPLEurl, token, password)
authhandler = urllib2.HTTPBasicAuthHandler(passmanager)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
page = urllib2.urlopen(PEOPLEurl).read()

print page #this will dump out all the people contacts in highrise

代码的任何反馈或建议都会有所帮助!

答案 2 :(得分:0)

我只是在查看其中一个php API wrappers的php代码,我看到他们使用curl;所以你看过pycurl ??

关于身份验证的

是一个你可以开始的例子(它没有经过测试)......

  import pycurl

  def on_receive(data):
      # process your data here
      pass

  def connetion(url, token)

      conn = pycurl.Curl()

      # Set Token.  
      conn.setopt(pycurl.USERPWD, "%s:x" % (token,)) 
      # the format TOKEN:x i get it from the PHP wrapper because usually the 
      # format should be USER:PASSWD so here i think they just use a token as
      # a USERname and they set the password to 'x'.

      conn.setopt(pycurl.URL, url)

      # Set the XML data to POST data.
      conn.setopt(pycurl.POSTFIELDS, XML_DATA)  

      # Add SSL.
      conn.setopt(pycurl.SSL_VERIFYPEER, 0)
      conn.setopt(pycurl.SSL_VERIFYHOST, 0)

      # Set function that will be called as soon as the data is received.
      conn.setopt(pycurl.WRITEFUNCTION, on_receive)

      # Perform the data transfer. 
      conn.perform() 

  if __name__ == '__main__':
      connection("http://yourcompany.highrisehq.com", your_token)

答案 3 :(得分:0)

有关如何进行基本身份验证的信息,请参阅here。此外,IIRC urllib还支持http://user:password@example.com个网址。