'NoneType'对象没有属性'group' [英] 'NoneType' object has no attribute 'group'
本文介绍了'NoneType'对象没有属性'group'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误:
AttributeError:'NoneType'对象没有属性'group'
追溯:
追溯(最近的最后一次呼叫):
文件youtube.py,第67行,位于< module>
videoUrl = getVideoUrl(content)
文件youtube.py,第11行,getVideoUrl
grps = fmtre.group(0).split('& amp;')
代码段:
(第66-71行)
content = resp.read()
videoUrl = getVideoUrl(content)
如果videoUrl不是None:
print('无法找到视频URL')
exit(1)
(行9-17)
def getVideoUrl(content):
fmtre = re.search('(?< = fmt_url_map =)。*',content)
grps = fmtre.group(0).split('&
vurls = urllib2.unquote(grps [0])
videoUrl =无
vurls.split('|')中的vurl:
如果vurl.find ('itag = 5')> 0:
return vurl
return无
解决方案
错误在您的行11中,您的 re.search
没有返回任何结果,即无
,以及那么你试图调用 fmtre.group
,但是 fmtre
是无
,因此 AttributeError
。
您可以尝试:
def getVideoUrl(content):
fmtre = re.search('(?< = fmt_url_map =)。*',content)
if fmtre是None:
return None
grps = fmtre.group(0).split('& amp;')
vurls = urllib2.unquote(grps [0])
videoUrl =无
vurls.split('|')中的vurl:
如果vurl.find('itag = 5')> 0:
返回vurl
返回无
Can somebody help me with this code? I'm trying to make a python script that will play videos and I found this file that download's Youtube videos. I am not entirely sure what is going on and I can't figure out this error.
Error:
AttributeError: 'NoneType' object has no attribute 'group'
Traceback:
Traceback (most recent call last):
File "youtube.py", line 67, in <module>
videoUrl = getVideoUrl(content)
File "youtube.py", line 11, in getVideoUrl
grps = fmtre.group(0).split('&')
Code snippet:
(lines 66-71)
content = resp.read()
videoUrl = getVideoUrl(content)
if videoUrl is not None:
print('Video URL cannot be found')
exit(1)
(lines 9-17)
def getVideoUrl(content):
fmtre = re.search('(?<=fmt_url_map=).*', content)
grps = fmtre.group(0).split('&')
vurls = urllib2.unquote(grps[0])
videoUrl = None
for vurl in vurls.split('|'):
if vurl.find('itag=5') > 0:
return vurl
return None
解决方案
The error is in your line 11, your re.search
is returning no results, ie None
, and then you're trying to call fmtre.group
but fmtre
is None
, hence the AttributeError
.
You could try:
def getVideoUrl(content):
fmtre = re.search('(?<=fmt_url_map=).*', content)
if fmtre is None:
return None
grps = fmtre.group(0).split('&')
vurls = urllib2.unquote(grps[0])
videoUrl = None
for vurl in vurls.split('|'):
if vurl.find('itag=5') > 0:
return vurl
return None
这篇关于'NoneType'对象没有属性'group'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文