如何使用Python访问37 signals Highrise的API?找到PHP/Ruby的包装器,但找不到Python。我现在正在编写我自己的代码,有谁有建议用Python克服身份验证的第一个障碍?
发布于 2011-09-06 04:40:09
我为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-06-14 12:47:27
我正要解决这个问题时,偶然发现了你的问题。这是我到目前为止所做的工作。它(目前)还不是很漂亮,但它是有效的。我不知道Pycurl,在看了一段时间后,我又回到了urllib2。Highrise使用基本身份验证,因此您不必使用CURL,您可以使用urllib2。你只需要通过所有的Pword管理器步骤。输出是一个包含所有公司或人员的长XML文件,具体取决于您插入的URL。如果你只想要一个人,你可以像‘http……/people/123.xml’或‘http……/people/123-fname-lname.xml’这样做(就像你在url中看到的那样,当你实际转到高层建筑中的联系人时,加上了.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任何关于这段代码的反馈或建议都会很有帮助!
发布于 2010-11-02 00:56:59
我刚刚查看了其中一个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)https://stackoverflow.com/questions/4070842
复制相似问题