473,799 Members | 3,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?Com mand=QueryConta iner&Container= %2FNowPlaying&R ecurse=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=DEC2D78EABF 48A6D; path=/; expires="Saturd ay,
16-Feb-2013 00:00:00 GMT";
WWW-Authenticate: Digest realm="TiVo DVR", nonce="FD08EF22 6909CA85", qop="auth"
Content-Length: 31
Content-Type: text/html
Connection: close

Digest realm="TiVo DVR", nonce="FD08EF22 6909CA85", 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?Con tainer=%2FNowPl aying&Command=Q ueryContainer&R ecurse=Yes"
print

theurl

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

passman = urllib2.HTTPPas swordMgrWithDef aultRealm()
passman.add_pas sword(None, theurl, username, password)
authhandler = urllib2.HTTPDig estAuthHandler( passman)
opener = urllib2.build_o pener(authhandl er)
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 HTTPBasicAuthHa ndler --> HTTPDigestAuthH andler. Any
ideas or help would be greatly appreciated!

Thanks,
-John

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

theurl =
"192.168.0. 25/TiVoConnect?Con tainer=%2FNowPl aying&Command=Q ueryContainer&R ecurse=Yes"
print theurl

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

authhandler = urllib2.HTTPDig estAuthHandler( )
authhandler.add _password("TiVo DVR",
"192.168.0. 25", username, password)
opener = urllib2.build_o pener(authhandl er)
urllib2.install _opener(opener)
try:
pagehandle = urllib2.urlopen (protocol + theurl)
print pagehandle.read lines()
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?Com mand=QueryConta iner&Container= %2FNowPlaying&R ecurse=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=DEC2D78EABF 48A6D; path=/; expires="Saturd ay,
16-Feb-2013 00:00:00 GMT";
WWW-Authenticate: Digest realm="TiVo DVR", nonce="FD08EF22 6909CA85", qop="auth"
Content-Length: 31
Content-Type: text/html
Connection: close

Digest realm="TiVo DVR", nonce="FD08EF22 6909CA85", 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?Con tainer=%2FNowPl aying&Command=Q ueryContainer&R ecurse=Yes"
print


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

theurl =
"192.168.1. 102/TiVoConnect?Con *tainer=%2FNowP laying&Command= Q*ueryContainer &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
1898
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 before this stuff rattles off your fingertips easily." -- Paul Rubin BJ MacNevin wants to run python from a CD. http://groups.google.com/groups?threadm=BhVyb.389117$Tr4.1144562@attbi_s03
1
2516
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 archive), McNab actually implements a different algorithm than hashcash. It might (or might not) be equivalent in security; but I cannot see any directly way to transform what he computes into an actual hashcash stamp. Barnes Connelly also...
13
3581
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 that I could write a program to identify patterns in the strings and then produce strings with similar patterns. He disagrees with me. He gave me 100 strings to analyze. I wrote a script to read each string and build a list of characters...
3
3192
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: urllib2 1a. You can add "handlers" to your opener indicating that you want to use HTTP Digest auth. This is nice way to handle it, but I don't see any way to use a custom verb in your URLOpener -- it always uses either GET or POST depending on...
1
2080
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 authentication. Please advise. thanks!!
2
2530
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 MapPoint service uses rfc2617 to authenticate the user. I have a working account for this which works using C# dotnet and Borland Delphi 6.0. When I try to authenticate using python it fail. Here is what I do to provoke the rfc2617 challenge:
13
2354
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 example. import urllib2 # Create an OpenerDirector with support for Basic HTTP Authentication...
2
3365
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 there's no Content-Length header and some other circumstances, so I have to tweak and modify the headers received slightly. But it works quite well with these hacks. Now I'd like to add proxy authentication so that I'm not running this open...
0
2352
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 digest authentication. To access this page, the browser asks for username/password. So far so good, the SWF works fine. Now, within that SWF, the script uses URLLoader to POST to another URL on the same server (but a different path than the page)....
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.