By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,457 Members | 1,304 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,457 IT Pros & Developers. It's quick & easy.

urllib.urlopen and https question

P: n/a
Hi,

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
Share this Question
Share on Google+
3 Replies


P: n/a
>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.

Cheers

Rich.

Jan 10 '06 #2

P: n/a
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

P: n/a
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.

rpd

"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.