是否有任何好的 Python 教程/指南可以将 XML-RPC 与 Last.fm API 结合使用? [英] Is there any good Python tutorial/guide to use XML-RPC with Last.fm API?

查看:21
本文介绍了是否有任何好的 Python 教程/指南可以将 XML-RPC 与 Last.fm API 结合使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 XML-RPC 的新手,我想知道是否有任何好的教程可以将 XML-RPC 与 Last.fm API 结合使用.

I'm new to XML-RPC and I would like to know if there is any good tutorial to use XML-RPC with the Last.fm API.

是否可以使用 xmlrpclib 模块调用 API 方法,如下例所示?

Is it possible to call the API methods using the xmlrpclib module like in the following example?

import xmlrpclib
myserver = xmlrpclib.ServerProxy('http://ws.audioscrobbler.com/2.0/')

推荐答案

你的代码看起来不错.

您可能不知道这一点,但大多数 XML-RPC 端点(例如 Last.fm 的)都支持 XML-RPC 内省.例如,如果您想了解它公开了哪些方法,请执行以下操作:

You might not know this, but most XML-RPC endpoints (such as Last.fm's) support XML-RPC introspection. For instance, if you want to find out what methods it exposes, do this:

import xmlrpclib
svc = xmlrpclib.ServerProxy('http://ws.audioscrobbler.com/2.0/')
print svc.system.listMethods()

您将获得 XML-RPC 端点公开的方法列表.

And you'll be given a list of the methods exposed by the XML-RPC endpoint.

顺便说一下,上面的那段代码演示了如何使用 ServerProxy 对象来调用它所绑定的端点公开的方法,在本例中为 system.listMethods 方法.如果您想调用 user.getTopTags(如 API 文档主页所示) 由 Last.fm 公开的方法,您可以这样做:

By the way, that bit of code up there demonstrates how to use a ServerProxy object to call a method exposed by the endpoint it's tied to, in this case, the system.listMethods method. If you wanted to call the user.getTopTags (as demonstrated on the API documentation homepage) method exposed by Last.fm, you'd do this:

print svc.user.getTopTags({'user': 'foo', 'api_key': 'bar'})

太简单了!当然,您需要从 Last.fm 获得 API 密钥,然后才能使用该 API.

Dead simple! Of course, you'll need an API key from Last.fm before you can use the API.

这篇关于是否有任何好的 Python 教程/指南可以将 XML-RPC 与 Last.fm API 结合使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆