用Python访问Highrise的API?

2024-05-14 20:55:50 发布

您现在位置:Python中文网/ 问答频道 /正文

如何使用Python访问37 signals Highrise的API?找到了PHP/Ruby的包装器,但没有Python。我现在正在写我自己的,有没有人建议我用Python克服身份验证的第一个障碍?在


Tags: 身份验证api建议phpruby障碍signalshighrise
3条回答

我正忙着解决这个问题,突然碰到你的问题。这是我迄今为止所破解的。虽然还不漂亮,但很管用。我不认识Pycurl,看了一会儿之后,我回到了urllib2。Highrise使用基本身份验证,所以不必使用CURL,可以使用urllib2。你只需要完成所有的程序管理器步骤。输出是一个很长的XML文件,其中包含所有公司或人员,具体取决于插入的URL。如果你只需要一个人,你可以做一些类似“http……/people/123.xml”或“http……/people/123 fname”之类的东西-名称.xml'(就像您在url中看到的,当您实际访问highrise中的联系人时,添加了.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

任何关于这个代码的反馈或建议都会很有帮助!在

我为Python编写了一个高层API包装器。它为每个高层类使用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安装:

^{pr2}$

请参阅here了解如何进行基本身份验证。IIRC urllib还支持http://user:password@example.comurl。在

相关问题 更多 >

    热门问题