473,320 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Python HTTP digest authentication woes...

I'm trying to access the XML version of my Tivo now playing list with
python. It uses auth digest HTTP authentication. I could really use
some help!

I'm able to get this page using curl:
curl --dump-header tivoHeaders --insecure --anyauth --user tivo:8000008
"https://192.168.1.102/TiVoConnect?Command=QueryContainer&Container=%2FNo wPlaying&Recurse=Yes"

But

when I use my python script, I get rejected:
https://192.168.1.102/TiVoConnect?Co...er&Recurse=Yes
Error

401
Server: tivo-httpd-1:7.1b-01-2:140
Set-Cookie: sid=DEC2D78EABF48A6D; path=/; expires="Saturday,
16-Feb-2013 00:00:00 GMT";
WWW-Authenticate: Digest realm="TiVo DVR", nonce="FD08EF226909CA85", qop="auth"
Content-Length: 31
Content-Type: text/html
Connection: close

Digest realm="TiVo DVR", nonce="FD08EF226909CA85", qop="auth"

I've scrounged for examples out there and the couple that I've found
just don't seem to work for me..

Here's one way I've tried:
=====================================
import urllib2

theurl =
"192.168.1.102/TiVoConnect?Container=%2FNowPlaying&Command=QueryC ontainer&Recurse=Yes"
print

theurl

protocol = 'https://'
username = 'tivo'
password = '8000008'

passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, theurl, username, password)
authhandler = urllib2.HTTPDigestAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
try:
pagehandle = urllib2.urlopen(protocol + theurl)
except IOError, e:
if hasattr(e, 'code'):
if e.code != 401:
print 'We got another error'
print e.code
else:
print "Error 401"
print e.headers
print e.headers['www-authenticate']
=======================================

I get 401 every time!
This was taken from an example online almost verbatim, the only major
thing I changed was HTTPBasicAuthHandler --> HTTPDigestAuthHandler. Any
ideas or help would be greatly appreciated!

Thanks,
-John

Jul 21 '05 #1
2 7473
I hacked this a little bit and it seems to do the trick.
import urllib2

theurl =
"192.168.0.25/TiVoConnect?Container=%2FNowPlaying&Command=QueryC ontainer&Recurse=Yes"
print theurl

protocol = 'https://'
username = 'tivo'
password = '1111111111'

authhandler = urllib2.HTTPDigestAuthHandler()
authhandler.add_password("TiVo DVR",
"192.168.0.25", username, password)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
try:
pagehandle = urllib2.urlopen(protocol + theurl)
print pagehandle.readlines()
except IOError, e:
if hasattr(e, 'code'):
if e.code != 401:
print 'We got another error'
print e.code
else:
print "Error 401"
print e.headers
print e.headers['www-authenticate']
Cheers

Dave

Aug 8 '05 #2

john wrote:
I'm trying to access the XML version of my Tivo now playing list with
python. It uses auth digest HTTP authentication. I could really use
some help!

I'm able to get this page using curl:
curl --dump-header tivoHeaders --insecure --anyauth --user tivo:8000008
"https://192.168.1.102/TiVoConnect?Command=QueryContainer&Container=%2FNo wPlaying&Recurse=Yes"

But

when I use my python script, I get rejected:
https://192.168.1.102/TiVoConnect?Co...er&Recurse=Yes
Error

401
Server: tivo-httpd-1:7.1b-01-2:140
Set-Cookie: sid=DEC2D78EABF48A6D; path=/; expires="Saturday,
16-Feb-2013 00:00:00 GMT";
WWW-Authenticate: Digest realm="TiVo DVR", nonce="FD08EF226909CA85", qop="auth"
Content-Length: 31
Content-Type: text/html
Connection: close

Digest realm="TiVo DVR", nonce="FD08EF226909CA85", qop="auth"

I've scrounged for examples out there and the couple that I've found
just don't seem to work for me..

Here's one way I've tried:
=====================================
import urllib2

theurl =
"192.168.1.102/TiVoConnect?Container=%2FNowPlaying&Command=QueryC ontainer&Recurse=Yes"
print


Oh yeah - I didn't spot this before....

theurl =
"192.168.1.102/TiVoConnect?Con*tainer=%2FNowPlaying&Command=Q*uer yContainer&Recurse=Yes"
this includes the parameters - which it shouldn't.

:-)

Fuzzy
http://www.voidspace.org.uk/python

Aug 8 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Emile van Sebille | last post by:
QOTW: "Have you ever used the copy module? I am *not* a beginner, and have used it *once* (and I can't remember what for, either)." -- Michael Hudson "It will likely take a little practice...
1
by: David Mertz, Ph.D. | last post by:
I decided to write a pure Python hashcash implementation. I have seen David McNab's Python implementation. Unfortunately, as near as I can tell (which is supported on the hashcash mailing list...
13
by: Brad Tilley | last post by:
A friend of mine wrote an algorithm that generates strings. He says that it's impossible to figure out exactly how the algorithm works. That may be true, but I think if I had enough sample strings...
3
by: John Reese | last post by:
Hello there. I've run into some missing functionality with HTTP Digest authentication in the 2.3 library and I was wondering if I'm just missing something. Missing functionality the first:...
1
by: Matt | last post by:
If I want to have a username/password dialog in my page, how can I add http header in ASP for username/password dialog? I want to hardcode the username/password in my page and check the...
2
by: trapeze.jsg | last post by:
Hi. Is there anybody who have tried to use python to access Microsofts MapPoint soap services? I am trying hard but I have run into a big thick wall called md5 digest authentication. The...
13
by: BartlebyScrivener | last post by:
New to Python and Programming. Trying to make scripts that will open sites and automatically log me on. The following example is from the urllib2 module. What are "realm" and "host" in this...
2
by: Dan Lenski | last post by:
Hi all, I've got a very simple HTML proxy server to access the web from my cell phone (based on this code: http://www.okisoft.co.jp/esc/python/proxy/). It's a very retarded phone that freezes if...
0
by: embeddedbob | last post by:
Hi there, I appreciate any help on the following issue. I can't seem to find any other similar topic. (CS4, ActionScript 3.0, Flash 10) I have a SWF embedded within a page that is protected by...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.