gpt4 book ai didi

python - 在Python中使用gdata Youtube API时出现套接字错误

转载 作者:行者123 更新时间:2023-12-03 05:43:14 40 4
gpt4 key购买 nike

我正在使用gdata通过以下代码将YouTube URL映射到视频标题:

import gdata.youtube.service as youtube
import re
import queue
import urlparse

ytservice = youtube.YouTubeService()
ytservice.ssl = True
ytservice.developer_key = '' # snip

class youtube(mediaplugin):
def __init__(self, parsed_url):
self.url = parsed_url
self.video_id = urlparse.parse_qs(parsed_url.query)['v'][0]
self.ytdata = ytservice.GetYouTubeVideoEntry(self.video_id)
print self.ytdata

调用service.GetYouTubeVideoEntry()时收到以下套接字异常:
  File "/Users/haldean/Documents/qpi/qpi/media.py", line 21, in __init__
self.ytdata = ytservice.GetYouTubeVideoEntry(self.video_id)
File "/Users/haldean/Documents/qpi/lib/python2.7/site-packages/gdata/youtube/service.py", line 210, in GetYouTubeVideoEntry
return self.Get(uri, converter=gdata.youtube.YouTubeVideoEntryFromString)
File "/Users/haldean/Documents/qpi/lib/python2.7/site-packages/gdata/service.py", line 1069, in Get
headers=extra_headers)
File "/Users/haldean/Documents/qpi/lib/python2.7/site-packages/atom/__init__.py", line 93, in optional_warn_function
return f(*args, **kwargs)
File "/Users/haldean/Documents/qpi/lib/python2.7/site-packages/atom/service.py", line 186, in request
data=data, headers=all_headers)
File "/Users/haldean/Documents/qpi/lib/python2.7/site-packages/atom/http_interface.py", line 148, in perform_request
return http_client.request(operation, url, data=data, headers=headers)
File "/Users/haldean/Documents/qpi/lib/python2.7/site-packages/atom/http.py", line 163, in request
connection.endheaders()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 937, in endheaders
self._send_output(message_body)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 797, in _send_output
self.send(msg)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 759, in send
self.connect()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1140, in connect
self.timeout, self.source_address)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
gaierror: [Errno 8] nodename nor servname provided, or not known

我不知道如何开始调试它。任何想法表示赞赏。谢谢!

编辑:
为了回应评论中提出的问题, video_idqh-mwjF-OMoparsed_url是:
ParseResult(scheme=u'http', netloc=u'www.youtube.com', path=u'/watch', params='', query=u'v=qh-mwjF-OMo&feature=g-user-u', fragment='')

最佳答案

我的错误是video_id应该作为关键字参数传递,如下所示:

    self.ytdata = ytservice.GetYouTubeVideoEntry(video_id=self.video_id)

套接字异常似乎是 gdata唯一会抛出异常的层;它会尝试根据参数盲目获取URL,并且只有在URL提取失败时才会失败。

关于python - 在Python中使用gdata Youtube API时出现套接字错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11814571/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com