471,086 Members | 1,084 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

urllib.urlopen and https question


I'm new to python. I've been handed the job of modifying a script we
have here at work that pulls content from a zope site, to create static
html. They wanted a check to make sure the database is up, while
pulling, to avoid errors.

I got it pretty much working how I want without any problems. It's
actually an error check I'm having a problem with.

Usernames and passwords change.... I'm using urlib.urlopen to open a
connection to a https url using the format of
https://username:password@url. This works great. However, if I put in
the wrong username, the python script prompts for user validation,
rather than giving an error.

The script is not interactive, will be run by cron. So I can't just let
it hang. I'm trying to figure out if there is a way to catch that
prompt and error out within the python script, rather that writing an
expect wrapper for it. The less interpeters I have to use, the better
for my cpu.

Jan 10 '06 #1
3 2298
>From the docs for urllib:

When performing basic authentication, a FancyURLopener instance calls
its prompt_user_passwd() method. The default implementation asks the
users for the required information on the controlling terminal. A
subclass may override this method to support more appropriate behavior
if needed.



Jan 10 '06 #2
That's what I get for scimming the documentation too quickly.

Got it, thanks!

For anyone else working on something similar, here is all I did... mind
you, this is my first experience with python.

# subclass of FancyURLopener so we can override the
prompt_user_password method
class DBCheckUrlOpener(urllib.FancyURLopener):
def prompt_user_passwd(self, host, realm):
"""3 args will be passed, so just catch them.
sys.exit("Bad user authentication for db check.")

Jan 10 '06 #3
Does anyone have an entire (simple) script for someone new to
programming and Python that will illustrate how to open an https site
and log on to it (with the script providing the username and password,
if that's possible). Thanks very much.


"Electricity is actually made up of extremely tiny particles called
electrons, that you cannot see with the naked eye unless you have been
drinking."--Dave Barry

Jan 10 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Gary Feldman | last post: by
reply views Thread by Russell E. Owen | last post: by
4 posts views Thread by Richard Shea | last post: by
3 posts views Thread by Volker M. | last post: by
1 post views Thread by John Hunter | last post: by
reply views Thread by Ali.Sabil | last post: by
reply views Thread by Cecil Westerhof | last post: by
4 posts views Thread by Mike Driscoll | last post: by

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.