# Can see PC videos from Tivo when pytivo is running from console but not from service



## John Cavanaugh (Dec 29, 2006)

New Premier Elite (14.9.2-01-2-758)
New pytivo,python and pywin install (python 2.7.2, latest pytivo, pywin32-216.win32-py2.7)

If I start pytivo from the console (pytivo.py) I can see my PC share on the Tivo and download videos just fine. However, if I am running pytivo as a service I see the MyMovies folder on the Tivo but nothing is in it.

pytivo.conf:

[Server]
port = 9032
ffmpeg = C:\pytivo\bin\ffmpeg.exe
tivo_mak = xxx
tivo_password = xxx
tivo_username = xxx
togo_path = f:\media
tivodecode = c:\pytivo\bin\tivodecode.exe
tdcat = c:\pytivo\bin\tivodecode.exe

[MyMovies]
type = video
path = f:\media

[_tivo_SD]

[_tivo_HD]

log.txt:

Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 88
Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 39
Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 94
Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 69
Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 73

I've also found that when I try to stop the service in Windows it tells me that it can't stop the service, but the services window shows it stopped - and then I can restart it.

I've walked through the troubleshooting page for pytivo and everything from that works fine (well other than it working as a service) - I can get to the web interface and make changes there without issue. If things are running from the command window, I don't see any errors:

C:\pytivo>pytivo.py
INFOyTivo.beacon:Announcing shares...
INFOyTivo.beacon:Registering: MyMovies
INFOyTivo.beacon:Scanning for TiVos...
INFOyTivoyTivo is ready.
INFOyTivo:192.168.1.137 [07/Jan/2012 15:29:05] "GET /TiVoConnect?Command=Query
Container&Container=%2F&DoGenres=1 HTTP/1.0" 200 -
INFOyTivo:192.168.1.137 [07/Jan/2012 15:29:07] "GET /TiVoConnect?Command=Query
Formats&SourceFormat=video%2Fx-tivo-mpeg HTTP/1.1" 200 -
INFOyTivo:192.168.1.137 [07/Jan/2012 15:29:07] "GET /TiVoConnect?Command=Query
Container&Container=MyMovies&SortOrder=!CaptureDate&ItemCount=8&Filter=x-tivo-co
ntainer%2Ftivo-videos,x-tivo-container%2Ffolder,video%2Fx-tivo-mpeg,video%2F*&Se
rialNum=7582001901FAE59 HTTP/1.1" 200 -
INFOyTivo:192.168.1.137 [07/Jan/2012 15:29:39] "GET /TiVoConnect?Command=Query
Formats&SourceFormat=video%2Fx-tivo-mpeg HTTP/1.1" 200 -
INFOyTivo:192.168.1.137 [07/Jan/2012 15:29:39] "GET /TiVoConnect?Command=Query
Container&Container=MyMovies&SortOrder=!CaptureDate&ItemCount=8&Filter=x-tivo-co
ntainer%2Ftivo-videos,x-tivo-container%2Ffolder,video%2Fx-tivo-mpeg,video%2F*&Se
rialNum=7582001901FAE59 HTTP/1.1" 200 -
INFOyTivo:192.168.1.137 [07/Jan/2012 15:30:23] "GET /TiVoConnect?Command=Query
Container&Container=MyMovies&SortOrder=!CaptureDate&ItemCount=8&Filter=x-tivo-co
ntainer%2Ftivo-videos,x-tivo-container%2Ffolder,video%2Fx-tivo-mpeg,video%2F*&Se
rialNum=7582001901FAE59 HTTP/1.1" 200 -
INFOyTivo:127.0.0.1 [07/Jan/2012 15:31:05] "GET / HTTP/1.1" 200 -
INFOyTivo:127.0.0.1 [07/Jan/2012 15:31:05] "GET /main.css HTTP/1.1" 200 -
INFOyTivo:127.0.0.1 [07/Jan/2012 15:31:05] code 404, message Not Found
INFOyTivo:127.0.0.1 [07/Jan/2012 15:31:05] "GET /favicon.ico HTTP/1.1" 404 -
INFOyTivo:127.0.0.1 [07/Jan/2012 15:35:39] "GET /TiVoConnect?Command=Settings&
Container=Settings HTTP/1.1" 200 -
INFOyTivo:127.0.0.1 [07/Jan/2012 15:35:39] "GET /main.css HTTP/1.1" 200 -
INFOyTivo:127.0.0.1 [07/Jan/2012 15:35:39] "GET /plugins/settings/settings.css
HTTP/1.1" 200 -
INFOyTivo:127.0.0.1 [07/Jan/2012 15:35:39] "GET /plugins/settings/settings.js
HTTP/1.1" 200 -
INFOyTivo:127.0.0.1 [07/Jan/2012 15:35:39] code 404, message Not Found
INFOyTivo:127.0.0.1 [07/Jan/2012 15:35:39] "GET /favicon.ico HTTP/1.1" 404 -

Ideas?

Thanks.


----------



## ThAbtO (Apr 6, 2000)

I just compared your pytivo.conf with mine and the only difference is there is an extra line "tdcat="


----------



## John Cavanaugh (Dec 29, 2006)

Wait, you have two "tdcat=" lines?

I have one in my conf file:

tdcat = c:\pytivo\bin\tivodecode.exe

Which I just saw was wrong, it should say:

tdcat = c:\pytivo\bin\tdcat.exe

I fixed that but i've still get errors in my log file when running as a service:

Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 88
Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 39
Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 94
Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 69


----------



## ThAbtO (Apr 6, 2000)

I do not any "tdcat=" line under the [server] line.

Also, I do not even have pytivo\bin\tdcat.exe

(Perhaps because my PyTivo is the WmcBrine version)


----------



## John Cavanaugh (Dec 29, 2006)

Hmm...ok, I could try removing that line for mine. I am running the latest wmcbrine version as well.


----------



## wmcbrine (Aug 2, 2003)

That line is not the issue. Please, let's not treat pyTivo.conf as a magical incantation. All that line does is tell pyTivo where tdcat is... and since that's the default location, the line is basically redundant.

John Cavanaugh, your log.txt (from service mode) is saying that the logging module can't write to the log file. Since no log file is specified in the pyTivo.conf file you've shown, I have to wonder if the service mode isn't actually using a different conf file.


----------



## ThAbtO (Apr 6, 2000)

I have debug.log as the log file and only noticed an error and it was saying it is missing a 'type=' for auto-push.


----------



## ThAbtO (Apr 6, 2000)

Do you have this in pytivo.conf? If not, copy/paste and change the path, if needed.

[handler_rotfile]
formatter = basicform
class = handlers.RotatingFileHandler
args = ('C:\pyTivo\debug.log', 'a', 10485760, 5)


----------



## John Cavanaugh (Dec 29, 2006)

wmcbrine said:


> That line is not the issue. Please, let's not treat pyTivo.conf as a magical incantation. All that line does is tell pyTivo where tdcat is... and since that's the default location, the line is basically redundant.
> 
> John Cavanaugh, your log.txt (from service mode) is saying that the logging module can't write to the log file. Since no log file is specified in the pyTivo.conf file you've shown, I have to wonder if the service mode isn't actually using a different conf file.


Interesting. I followed the directions on the wiki to set things up, so I took the stock conf file, copied it to pytivo.conf and then edited it with the web interface. Once I did that it removed everything except what I listed in my original message.

I'll try taking the handler_rotfile section from ThAbtO's message, copying that in and see if it makes a difference. Thanks.


----------



## John Cavanaugh (Dec 29, 2006)

Stopped the service (still getting an error stopping it), copied the rotfile section from above into my pytivo.conf, started the service and i'm still getting the following in my log.txt file:

Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 88
Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 39
Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 94
Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 69

It does look like it's ignoring the new section as things are going to the log.txt and not the debug.txt as i've specified.

Hmmm....


----------



## ThAbtO (Apr 6, 2000)

The log all seem to point to 1 thing:

File "C:\Python27\lib\logging\__init__.py"

Python 2.7 and if I remember correctly, there were problems with that version and PyTivo.

I have version 2.6.


----------



## wmcbrine (Aug 2, 2003)

There are NOT problems with that version and pyTivo. The only problem was with the "Windows Installer" package not finding it. That package is long obsolete.


----------



## John Cavanaugh (Dec 29, 2006)

wmcbrine said:


> There are NOT problems with that version and pyTivo. The only problem was with the "Windows Installer" package not finding it. That package is long obsolete.


Thanks for the update wmcbrine. Do you have any other ideas of what I can do/try to get things to work?

Thanks.


----------



## windracer (Jan 3, 2003)

Is the service running with administrator rights? Maybe it doesn't have permission to write to the logfile location?


----------



## John Cavanaugh (Dec 29, 2006)

windracer said:


> Is the service running with administrator rights? Maybe it doesn't have permission to write to the logfile location?


Good thought - and i'll confirm it tonight when I get home but I don't think that's it. This is an XP box and i'm the only user - and i'm an admin. 

[Edit: But I don't think I opened the DOS box to install the service "as an administrator".]

Thanks.


----------



## John Cavanaugh (Dec 29, 2006)

pyTivo service is using the local system account...so I don't think it's a privilege issue.


----------



## John Cavanaugh (Dec 29, 2006)

Ok. Had some more time to play with this today. Ripped everything out and started over again. Grabbed the latest packages (Python 2.7.2, the latest wmcbrine and pywin32-216.win32-py2.7.exe packages) installed then per the wiki and i'm getting the same results - can see things on the Tivo under MyMovies if I run pytivo from the console but not when I run it as a service.

There has been a change in behavior though - when I run pytivo from the console, all of the entries in my f:\media directory are listed as if they all exist in the root of that directory instead of listing all of the directories in f:\media.

pytivo.conf:

[Server]
port = 9032
ffmpeg = c:\pyTivo\bin\ffmpeg.exe
tivo_mak = xxx
tivo_password = xxx
tivo_username = xxx
togo_path = f:\media

[MyMovies]
type = video
path = f:\media

[_tivo_SD]

[_tivo_HD]

output from log.txt:

Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 88
Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 39
Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 94
Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 866, in emit
self.flush()
File "C:\Python27\lib\logging\__init__.py", line 828, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Logged from file beacon.py, line 69

Tried to put the logging section that ThAbtO recommended, stopped and restarted the server and I still get the same output error messages - in log.txt and not debug.txt.

Anyone have any other ideas?

Thanks.


----------



## ThAbtO (Apr 6, 2000)

Is that the complete pytivo.conf file? my file is considerably longer.


----------



## John Cavanaugh (Dec 29, 2006)

ThAbtO said:


> Is that the complete pytivo.conf file? my file is considerably longer.


Thanks for the reply. Yes, that's the whole file.

The pytivo.conf.dist file looks like this:

# This is an example config file, showing all the options. You probably 
# won't need most of them. Your working config file will be named 
# "pyTivo.conf". '#' starts a comment. It is recommended that
# that you use the Web Administration tool to modify pyTivo.conf after
# you get pyTivo up and running. You can access the tool by pointing your
# browser to http://localhost:9032/

[Server]
port=9032

# Full path to ffmpeg including filename
# For windows: ffmpeg=c:\Program Files\pyTivo\bin\ffmpeg.exe
# For linux: ffmpeg=/usr/bin/ffmpeg
#ffmpeg=c:\Program Files\pyTivo\bin\ffmpeg.exe
ffmpeg=/usr/bin/ffmpeg

# Setting this to True will log more ouput for debugging purposes.
#debug=False

# Max video bitrate, default 30000k
# sets ffmpeg -maxrate setting to minimize bitrate peak playback issues.
# mpegs with video bitrate above this setting will also be transcoded.
#MAX_VIDEO_BR=17408k

# Audio bit-rate, defaults to 192K for S2, 384K for S3/HD
#audio_br=320K

# Video bit-rate, defaults to 4096K for S2, 8192K for S3/HD
#video_br=12Mi

# Beacon broadcast address(es)
# The default is 255.255.255.255, but on some multihomed machines you 
# may need to specify the subnet broadcast address(es) of your Tivo 
# boxes. You can also specify "listen" to listen for direct connection 
# attempts on port 2190, for use with the "Manually add a server..." 
# function. (And if you set beacon to listen _only_, it turns off 
# broadcasts.)
#beacon=192.168.1.255 listen

# Output Pixel Width:
# Width, defaults to 544 for S2, 1920 for S3/HD
# Height, defaults to 480 for S2, 1080 for S3/HD
# Valid widths: [S3/HD = 1920, 1440, 1280], [S2/S3/HD = 720, 704, 544, 480, 352]
# Valid heights: [S3/HD = 1080, 720], [S2/S3/HD = 480]
#width=1920
#height=1080
#ffmpeg_tmpl=%(video_codec)s %(video_fps)s %(video_br)s %(max_video_br)s %(buff_size)s %(aspect_ratio)s %(audio_br)s %(audio_fr)s %(audio_ch)s %(audio_codec)s %(ffmpeg_pram)s %(format)s

# Togo settings:
# Set this up if you wish to have TiVo ToGo support. This allows you to
# copy videos from your TiVo via a web page. 
#
#tivo_mak=<Your Media Access Key>
#togo_path=<path where movies will go or a section name>

# Per tivo options
# section named _tivo_TSN with the tsn in all caps
#[_tivo_00000DEADBEEF]

# If you want to use 16:9 or 4:3 on this tivo
#aspect169=true

#width=1440
#height=720
#audio_br=320K
#video_br=12Mi
#ffmpeg_tmpl=%(video_codec)s %(video_fps)s %(video_br)s %(max_video_br)s %(buff_size)s %(aspect_ratio)s %(audio_br)s %(audio_fr)s %(audio_ch)s %(audio_codec)s %(ffmpeg_pram)s %(format)s

#[_tivo_HD]
# section for default video options applicable to all HD TiVos
# see pyTivo Web Configuration for all available settings

#[_tivo_SD]
# section for default video options applicable to all SD TiVos
# see pyTivo Web Configuration for all available settings

[MyMovies]
# Type can be 'video', 'music', or 'photo'
type=video

# Path is the full path to your files (No trailing slash needed)
# For windows: path=c:\videos
# For linux: path=/media
path=/home/armooo/Videos

# You can have more than one share
#[MyTelevision]
#type=video
#path=d:\television

As per the Wiki, I copied this file to pytivo.conf, started the service, went into the web interface and updated the ffmpeg path, tivo_username, tivo_password, tivo_mak and togo_path in the Global Server Settings and then the path in the MyMovies section. Saved everything and did a soft reset. The resulting pytivo.conf file is what I listed above.


----------



## Speed Daemon (Jan 15, 2012)

John Cavanaugh said:


> Good thought - and i'll confirm it tonight when I get home but I don't think that's it. This is an XP box and i'm the only user - and i'm an admin.
> 
> [Edit: But I don't think I opened the DOS box to install the service "as an administrator".]
> 
> Thanks.


I'm not familiar with pytivo, and don't know how the Windows service is being created. I can only assume that the software includes the correct tools. One thought is that since Python is an interpreter, you'll want to make sure that the Python files have the right permissions as well.

As a general rule, I start at each top level directory and first take ownership recursively as Administrator, with full permissions. It's important to do this as THE Administrator, not just as a member of the Administrators group, because some arcane things can only be done by Administrator. Next, change the group permissions recursively to full permissions for Administrators, SYSTEM and SERVICE. Don't inherit any other owners or groups. Once this is done, install the service.

BTW, if you need to run a command line to install the service, be sure to use the Windows command interpreter, CMD.EXE, and not a "DOS box" (COMMAND.COM). Again, it's best to do this as Administrator, not just as a member of the Administrators group.


----------



## moyekj (Jan 24, 2006)

The other thing you should do is *run the pyTivo service using the same account that you login with * instead of the default Windows service account. That should eliminate any user permissions type issues. To do that something like:

* Control Panel->Administrative Tools->Services
* Scroll down and find pyTivo entry
* Right click on pyTivo and stop service if it is running
* Right click on pyTivo and select Properties
* Choose Log On tab
* Click on "This account" and type in account name that you use to login to your computer along with the password to go along with it.
* OK the form
* Now start the service again


----------



## John Cavanaugh (Dec 29, 2006)

Thanks for the replies and ideas guys. I'll look into them. The thing I keep coming back to (and maybe I shouldn't) is that up until 2 weeks ago before my Series 3 died I had a perfectly working pytivo install running as a service. Everything worked fine - directories were shown properly on the S3 and I could push and pull things to/from my PC without issue.

When my S3 died and I replaced it with the Elite I had hoped that my existing installation would "just work" as well but it didn't. I was told that while things should "just work" it would be better to update everything to the latest version rather than trying to diagnose what was wrong with my old version - so I did.

I don't remember exactly how I did things with my old install (since it was a few years ago) but I believe I used the (then) current Windows installer version of pytivo which just took care of the service install, etc. itself.


----------



## ThAbtO (Apr 6, 2000)

My PyTivo.conf


```
[loggers]
keys = root

[_tivo_SD]


[handler_console]
formatter = basicform
class = StreamHandler
args = (sys.stdout,)

[I-Extend]
Type = video
path = i:\

[handlers]
keys = console,rotfile

[Admin]
tivo_mak = {removed}
togo_path = i:\video
type = admin

[handler_rotfile]
formatter = basicform
class = handlers.RotatingFileHandler
args = ('E:\pyTivo\debug.log', 'a', 10485760, 5)

[Server]
tivo_password =  {removed}
tivo_mak =  {removed}
ffmpeg = e:\pyTivo\bin\ffmpeg.exe
temp = h:\cache\pyTivo
togo_path = i:\video
tivo_username =  {removed}
port = 9032

[formatter_basicform]
format = %(asctime)s %(levelname)-5s %(name)s: %(message)s

[Photos]
type = photo
path = g:\news

[music]
type = music
path = g:\news\mp3s

[_tivo_HD]

[logger_root]
handlers = console,rotfile
level = DEBUG

[formatters]
keys = basicform
```


----------



## MassD (Sep 19, 2002)

I JUST ran into this exact same issue... if I run manually, I can see the share and recordings, but if I run as a service, I only see the share.

I poked around a bit, tried all sorts of things, but then I went in and checked the dropped packets on my firewall... when PyTivo ran as a service, the firewall was blocking port 9032. I punched a hole for that TCP port and viola! I saw my movies within seconds.


----------



## ScaryMike (Aug 23, 2002)

MassD said:


> I JUST ran into this exact same issue... if I run manually, I can see the share and recordings, but if I run as a service, I only see the share.
> 
> I poked around a bit, tried all sorts of things, but then I went in and checked the dropped packets on my firewall... when PyTivo ran as a service, the firewall was blocking port 9032. I punched a hole for that TCP port and viola! I saw my movies within seconds.


I was having this exact problem and your solution was perfect! thanks!


----------



## Dufusyte (Feb 28, 2013)

MassD said:


> I punched a hole for that TCP port


A safer way is to make a Firewall Exception for just PythonService.exe, instead of opening port 9032 to everything. Hackers sometimes scan for open ports...


----------

