【问题标题】:python TypeError : unbound method UpdateVideoEntry() must be called with YouTubeService instancepython TypeError:必须使用 YouTubeService 实例调用未绑定的方法 UpdateVideoEntry()
【发布时间】:2012-09-24 15:40:17
【问题描述】:

我正在尝试使用 youtube api 更新条目。这是我正在努力解决的错误:

Traceback(最近一次调用最后一次):文件“”,第 1 行,in updated_entry = gdata.youtube.service.YouTubeService.UpdateVideoEntry(YTVentry.id) TypeError:必须调用未绑定的方法 UpdateVideoEntry() YouTubeService 实例作为第一个参数(得到 NoneType 实例 而是)

这是我的代码:

    import gdata.youtube
    import gdata.youtube.service
    import gdata.youtube.data
client = gdata.youtube.service.YouTubeService()    
...
videos_feed = client.GetYouTubeVideoFeed(uri)
    for entry in videos_feed.entry:
    print entry.title.text
        YTentry = entry._GDataEntry__GetId
        YTVentry = gdata.youtube.YouTubeVideoEntry(YTentry)
        YTVentry.media.title = '09.11.2012 Hold me close'
        YTVentry.media.description = '09.11.2012 : Hold me close section'
        updated_entry = gdata.youtube.service.YouTubeService.UpdateVideoEntry(YTVentry.id)

根据谷歌 gdata youtube 文档:

要更新视频元数据,只需更新 YouTubeVideoEntry 对象 然后使用 YouTubeService 对象的 UpdateVideoEntry 方法。这个 方法将包含更新的 YouTubeVideoEntry 作为参数 元数据。

提前致谢。

【问题讨论】:

    标签: python youtube


    【解决方案1】:
        updated_entry = gdata.youtube.service.YouTubeService.UpdateVideoEntry(YTVentry.id)
    

    应该是

        updated_entry = client.UpdateVideoEntry(YTVentry.id)
    

    gdata.youtube.service.YouTubeService.UpdateVideoEntry(YTVentry.id) TypeError:必须调用未绑定的方法 UpdateVideoEntry() YouTubeService 实例作为第一个参数(得到 NoneType 实例 而是)

    错误是因为您尝试从类而不是您创建的客户端对象调用 UpdateVideoEntry。您已经创建了一个 YouTubeService 对象 client,您需要使用它而不是直接调用类的方法。

    【讨论】:

      【解决方案2】:

      您是在 YouTubeService 类上调用该方法,而不是在该类的实例上。换句话说,您应该调用 client.UpdateVideoEntry(...) 而不是 YouTubeService.UpdateVideoEntry(...),就像您对 API 的其他调用一样。

      文档甚至说您应该在 YouTubeService 对象上调用该方法,而不是在类上。

      错误信息表明您可以直接调用类方法,但必须将类的实例作为第一个参数传递。当您在实例上调用方法时,这是隐式完成的,但在调用类上的方法时必须显式完成。否则 Python 将不知道该方法应该在哪个实例上运行(即 self 是什么)。

      【讨论】:

        猜你喜欢
        • 2014-12-10
        • 1970-01-01
        • 1970-01-01
        • 2016-09-15
        • 2017-04-03
        • 2014-09-10
        • 1970-01-01
        • 2017-07-24
        • 2015-06-19
        相关资源
        最近更新 更多