LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 02-08-2015, 01:12 PM   #1
glupa4e
Member
 
Registered: Jan 2011
Posts: 321

Rep: Reputation: 7
Unhappy 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.

Thanks!
 
Old 02-08-2015, 03:20 PM   #2
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
Well, it's really a bug in the livestreamer code.

They test to see if a playlist line matches...
Code:
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.

IMO, the line
Code:
return match.group("tag"), match.group("value").strip()
should be replaced with
Code:
val = match.group("value")
return match.group("tag"), val.strip() if val else None
Welcome to dynamic scripting languages.
 
Old 02-09-2015, 01:57 PM   #3
glupa4e
Member
 
Registered: Jan 2011
Posts: 321

Original Poster
Rep: Reputation: 7
hello Richard Cranium,

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?

thanks
 
Old 02-09-2015, 09:59 PM   #4
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
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.)
 
Old 02-10-2015, 02:05 PM   #5
glupa4e
Member
 
Registered: Jan 2011
Posts: 321

Original Poster
Rep: Reputation: 7
Hello again Richard Cranium,

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.

Thank you for your cooperation!
 
Old 02-10-2015, 06:09 PM   #6
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
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.
 
Old 08-20-2016, 10:27 AM   #7
glupa4e
Member
 
Registered: Jan 2011
Posts: 321

Original Poster
Rep: Reputation: 7
Question Slackware 14.2 Upgrade

Hello,

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'
Could this error be fixed anyhow?
 
Old 08-20-2016, 11:57 AM   #8
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
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.
 
Old 08-20-2016, 05:36 PM   #9
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
glupa4e, please submit an new issue on the livestreamer github page and tell them what you just told us.

This is a bug in livestreamer and it needs to be fixed by the developers.
 
Old 08-21-2016, 07:06 AM   #10
glupa4e
Member
 
Registered: Jan 2011
Posts: 321

Original Poster
Rep: Reputation: 7
Hi Guys,

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.
 
Old 08-21-2016, 05:49 PM   #11
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
Quote:
Originally Posted by glupa4e View Post
Hi Guys,

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.
 
1 members found this post helpful.
Old 08-21-2016, 07:10 PM   #12
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by glupa4e View Post
Hi Guys,

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.
 
Old 08-23-2016, 02:26 AM   #13
glupa4e
Member
 
Registered: Jan 2011
Posts: 321

Original Poster
Rep: Reputation: 7
Hi Guys,

thanks for your piece of advice. I submitted an issue to the Livestreamer developers.
 
1 members found this post helpful.
Old 08-23-2016, 10:43 AM   #14
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
Quote:
Originally Posted by glupa4e View Post
Hi Guys,

thanks for your piece of advice. I submitted an issue to the Livestreamer developers.
Thanks! Despite my whining, code doesn't get better if nobody knows about problems.
 
Old 08-29-2016, 01:35 PM   #15
glupa4e
Member
 
Registered: Jan 2011
Posts: 321

Original Poster
Rep: Reputation: 7
Smile Thanks to GitHub developers

Changing Line 99 in the file
Code:
/usr/lib64/python2.7/site-packages/livestreamer/stream/hls_playlist.py
to
Code:
match = re.match("#(?P[\w-]+)(:(?P.+))", line)
solved my problem.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python :: AttributeError: 'module' object has no attribute 'interfaces' golden_boy615 Programming 4 12-19-2014 09:22 AM
Python: AttributeError: 'module' object has no attribute 'main' mdooligan Linux - Software 1 09-29-2013 09:30 PM
AttributeError: 'module' object has no attribute 'error' cmnorton Programming 1 04-09-2009 05:45 PM
python: AttributeError: 'list' object has no attribute 'Append' browny_amiga Programming 3 01-12-2009 04:58 AM
gentoo env-update AttributeError: 'module' object has no attribute 'env_update' linux_mopper Linux - Newbie 2 08-06-2008 01:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 12:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration