0

如何使用 Python 访问 37 个信号 Highrise 的 API?找到 PHP/Ruby 的包装器,但不是 Python。我现在正在编写自己的代码,有人对使用 Python 克服身份验证的第一个障碍有什么建议吗?

4

4 回答 4

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
于 2011-09-05T20:40:08.733 回答
1

当我偶然发现你的问题时,我只是在解决这个问题。到目前为止,这是我一起破解的。它(还)不漂亮,但它有效。我不知道 Pycurl,看了一会儿我又回到了 urllib2。Highrise 使用基本身份验证,因此您不必使用 CURL,您可以使用 urllib2。您只需完成所有 Pword Manager 步骤。输出是所有公司或人员的长 XML 文件,具体取决于您插入的 URL。如果你只想要一个人,你可以做一些类似'http....../people/123.xml'或'http....../people/123-fname-lname.xml'的事情(就像你看到的当您实际访问添加了 .xml 的高层联系人时,在 url 中)。

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

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

于 2011-06-14T04:47:27.470 回答
0

我只是在查看其中一个php API 包装器的 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)
于 2010-11-01T16:56:58.967 回答
0

请参阅此处了解如何进行基本身份验证。IIRC urllib 也支持http://user:password@example.comURL。

于 2010-11-01T16:57:07.880 回答