[SOLVED] Python 2.7 - AttributeError: 'NoneType' object has no attribute 'strip'
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Python 2.7 - AttributeError: 'NoneType' object has no attribute 'strip'
Hello,
i am trying to decode one stream and push it to a player instead of watching it in a browser. I am using livestreamer for this purpose. Unfortunately I am getting error when i try it out:
Code:
bash-4.2$ livestreamer hlsvariant://http://domain/path_to_playlist/playlist.m3u8 best
[cli][info] Found matching plugin stream for URL hlsvariant://http://domain/path_to_playlist/playlist.m3u8
[cli][info] Available streams: 142k (worst), 180p, 272p, 360p, 720p (best)
[cli][info] Opening stream: 720p (hls)
Traceback (most recent call last):
File "/usr/bin/livestreamer", line 9, in <module>
load_entry_point('livestreamer==1.11.1', 'console_scripts', 'livestreamer')()
File "/usr/lib64/python2.7/site-packages/livestreamer_cli/main.py", line 851, in main
handle_url()
File "/usr/lib64/python2.7/site-packages/livestreamer_cli/main.py", line 470, in handle_url
handle_stream(plugin, streams, stream_name)
File "/usr/lib64/python2.7/site-packages/livestreamer_cli/main.py", line 357, in handle_stream
success = output_stream(stream)
File "/usr/lib64/python2.7/site-packages/livestreamer_cli/main.py", line 227, in output_stream
stream_fd, prebuffer = open_stream(stream)
File "/usr/lib64/python2.7/site-packages/livestreamer_cli/main.py", line 204, in open_stream
stream_fd = stream.open()
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls.py", line 254, in open
reader.open()
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/segmented.py", line 185, in open
self.worker = self.__worker__(self)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls.py", line 121, in __init__
self.reload_playlist()
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls.py", line 134, in reload_playlist
playlist = hls_playlist.load(res.text, res.url)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py", line 275, in load
return parser(base_uri).parse(data)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py", line 241, in parse
self.parse_line(lineno, line)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py", line 193, in parse_line
self.m3u8.allow_cache = self.parse_tag(line, self.parse_bool)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py", line 143, in parse_tag
tag, value = self.split_tag(line)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py", line 102, in split_tag
return match.group("tag"), match.group("value").strip()
AttributeError: 'NoneType' object has no attribute 'strip'
I do not know now if there is a problem with the stream itself, or it is the livestreamer or python that generates that error. I know that this is not Slackware specific issue but if anyone has got experience with such things might share their knowledge.
match = re.match("#(?P<tag>[\w-]+)(:(?P<value>.+))?", line)
However, the "value" expression can happen 0 or 1 times. You've got a case of 0 times. Since there's no match for the "value" expression, you get a None object (essentially a null pointer) instead of a string. None objects don't have a strip method but string objects do. The bug is that they call strip() instead of checking to see if the match is None.
thank you for your post. I think i got what the problem is. What i did not grasp is - should i by myself modify something in the code or not? And if yes, where and how should i do that? Or just wait and be patient until the livestreamer developers correct this error?
I'd send them the traceback along with a copy of your playlist (assuming that you don't mind someone else seeing it).
You could also change your playlist to match the pattern they *really* expect. As a last resort, you could change your copy of /usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py to match what I wrote above. (I'm not certain that returning None for the tag's value would really work; it could just cause a problem somewhere else.)
thank you for posting. Of course i do not mind, you sending them my playlist.
By the way i made the changes you had proposed but i got another error:
Code:
Traceback (most recent call last):
File "/usr/bin/livestreamer", line 9, in <module>
load_entry_point('livestreamer==1.11.1', 'console_scripts', 'livestreamer')()
File "/usr/lib64/python2.7/site-packages/livestreamer_cli/main.py", line 851, in main
handle_url()
File "/usr/lib64/python2.7/site-packages/livestreamer_cli/main.py", line 450, in handle_url
streams = fetch_streams(plugin)
File "/usr/lib64/python2.7/site-packages/livestreamer_cli/main.py", line 367, in fetch_streams
sorting_excludes=args.stream_sorting_excludes)
File "/usr/lib64/python2.7/site-packages/livestreamer/plugin/plugin.py", line 313, in get_streams
return self.streams(*args, **kwargs)
File "/usr/lib64/python2.7/site-packages/livestreamer/plugin/plugin.py", line 227, in streams
ostreams = self._get_streams()
File "/usr/lib64/python2.7/site-packages/livestreamer/plugins/stream.py", line 73, in _get_streams
streams = cls(self.session, urlnoproto, **params)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls.py", line 278, in parse_variant_playlist
parser = hls_playlist.load(res.text, base_uri=res.url)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py", line 281, in load
return parser(base_uri).parse(data)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py", line 247, in parse
self.parse_line(lineno, line)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py", line 201, in parse_line
self.state["streaminf"] = self.parse_tag(line, self.parse_attributes)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py", line 152, in parse_tag
value = transform(value)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py", line 116, in parse_attributes
attr = re.findall(ATTRIBUTE_REGEX, value)
File "/usr/lib64/python2.7/re.py", line 177, in findall
return _compile(pattern, flags).findall(string)
TypeError: expected string or buffer
That is why i made a roll back so now i am getting the first error.
It doesn't surprise me that my code change suggestion moved the error somewhere else.
Please note that I don't work on livestreamer code; I've just done a lot of python programming.
i installed Slackware 14.2 and all optional and mandatory packages for livestreamer from Slackbuilds repository. I still get the error:
Code:
[cli][info] Available streams: 142k (worst), 180p, 272p, 360p, 720p (best)
[cli][info] Opening stream: 720p (hls)
Traceback (most recent call last):
File "/usr/bin/livestreamer", line 9, in <module>
load_entry_point('livestreamer==1.12.2', 'console_scripts', 'livestreamer')()
File "/usr/lib64/python2.7/site-packages/livestreamer_cli/main.py", line 886, in main
handle_url()
File "/usr/lib64/python2.7/site-packages/livestreamer_cli/main.py", line 491, in handle_url
handle_stream(plugin, streams, stream_name)
File "/usr/lib64/python2.7/site-packages/livestreamer_cli/main.py", line 378, in handle_stream
success = output_stream(stream)
File "/usr/lib64/python2.7/site-packages/livestreamer_cli/main.py", line 245, in output_stream
stream_fd, prebuffer = open_stream(stream)
File "/usr/lib64/python2.7/site-packages/livestreamer_cli/main.py", line 222, in open_stream
stream_fd = stream.open()
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls.py", line 258, in open
reader.open()
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/segmented.py", line 185, in open
self.worker = self.__worker__(self)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls.py", line 125, in __init__
self.reload_playlist()
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls.py", line 138, in reload_playlist
playlist = hls_playlist.load(res.text, res.url)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py", line 279, in load
return parser(base_uri).parse(data)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py", line 245, in parse
self.parse_line(lineno, line)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py", line 197, in parse_line
self.m3u8.allow_cache = self.parse_tag(line, self.parse_bool)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py", line 147, in parse_tag
tag, value = self.split_tag(line)
File "/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py", line 102, in split_tag
return match.group("tag"), match.group("value").strip()
AttributeError: 'NoneType' object has no attribute 'strip'
Did you submit a bug report to the livestream developers the first time around? You should give them the traceback and your playlist so they can reproduce the problem.
I'll stress again that I don't work on livestream, nor do I use it. I will not submit a bug report on this.
I looked closer at the livestreamer codebase, and I don't believe that the developers have seen a playlist with the entries that you have. (I think the livestream code base could use some unit tests to verify that the code can handle None return values in various places, but that's merely my opinion.)
You can try the following, but I don't think that it will work:
Edit the file /usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py. On line 99, you will find the line..
Code:
match = re.match("#(?P<tag>[\w-]+)(:(?P<value>.+))?", line)
Delete the last question mark on that line and save the file.
The stuff marked out won't work and will simply result in the same error (moved to different line numbers) as the last time you tried.
i have still not submitted an issue to Livestreamer. I thought one should be a developer to submit such issues but i am not. But if no one else wants to do that, i should create an account and try to describe the issue.
i have still not submitted an issue to Livestreamer. I thought one should be a developer to submit such issues but i am not. But if no one else wants to do that, i should create an account and try to describe the issue.
If only that were true. It would certainly cut down on the number of bug reports that I get in the Day Job.
i have still not submitted an issue to Livestreamer. I thought one should be a developer to submit such issues but i am not. But if no one else wants to do that, i should create an account and try to describe the issue.
Your description of the issue here is perfect. Just tell them what you told us.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.