473,811 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

urllib.urlopen and https question

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
3 2425
>From the docs for urllib:

When performing basic authentication, a FancyURLopener instance calls
its prompt_user_pas swd() 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
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_pas sword method
class DBCheckUrlOpene r(urllib.FancyU RLopener):
def prompt_user_pas swd(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.

rpd

"Electricit y 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5197
by: Gary Feldman | last post by:
I think I've found a deficiency in the design of urllib related to https. In order to complete an https connection, it appears that URLOpener and hence FancyURLOpener require the key and cert files. Or at least, it's not clear from the description of socket.ssl what it does if they're omitted. However, urlopen has no way to specify such things. Nor should it - for typical uses, a person simply trying to retrieve data from an ssl site...
0
1328
by: Russell E. Owen | last post by:
I'm using urllib.urlopen() to retrieve data via ftp. I'm using Tkinter to display progress and so using a file even handler to read the data. My question is whether there's some easy way to do a nonblocking read? Here's a brief summary of the code: class ftpget: def __init__(self, url): self.bytesRead = 0
4
3998
by: Richard Shea | last post by:
Hi - I'm new to Python. I've been trying to use URLLIB and the 'tidy' function (part of the mx.tidy package). There's one thing I'm having real difficulties understanding. When I did this ... finA= urllib.urlopen('http://www.python.org/') foutA=open('C:\\testout.html','w') tidy(finA,foutA,None) I get ...
3
2042
by: Volker M. | last post by:
Hey, I want to open a list of URLs with Pythons urllib and the fuction open(URL) automatically. It is important that the program open ONLY normal http-sites and no https-sites with user/password-request. So exists a possibility that I could cancel all site requests with user/password-dialogues? Thx
1
2500
by: John Hunter | last post by:
I have a test script below which I use to fetch urls into strings, either over https or http. When over https, I use m2crypto.urllib and when over http I use the standard urllib. Whenever, I import sockets and setdefaulttimeout, however, using m2crypto.urllib tends to cause a http.BadStatusLine to be raised, even if the timeout is set to be very large. All of the documents in the test script can be accessed publicly. Any ideas? Is...
0
2453
by: Ali.Sabil | last post by:
hello all, I just maybe hit a bug in both urllib and urllib2, actually urllib doesn't support proxy authentication, and if you setup the http_proxy env var to http_proxy=http://user:passwd@host:port/ and https_proxy=$http_proxy i get a traceback : Traceback (most recent call last): File "test_urllib.py", line 2, in ? urllib.urlopen("https://sf.net/")
0
1357
by: Cecil Westerhof | last post by:
I have a strange problem. I wrote a script that uses urllib.urlopen to fetch a page through https. In Python 2.2.2 this works without a problem. But when I use the script in Python I get: Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/local/lib/python2.4/urllib.py", line 79, in urlopen return opener.open(url, data) File "/usr/local/lib/python2.4/urllib.py", line 177, in open return...
0
1351
by: gmguyx | last post by:
I tried using urllib.urlopen to open a personalized webpage (my.yahoo.com) but it doesn't work: print urllib.urlopen(http://my.yahoo.com).read() Instead of returning my.yahoo.com, it returns a page asking me to log in. So then I tried urllib.urlencode:
4
5532
by: Mike Driscoll | last post by:
Hi, I have been using the following code for over a year in one of my programs: f = urllib2.urlopen('https://www.companywebsite.com/somestring') It worked great until the middle of the afternoon yesterday. Now I get the following traceback:
0
9734
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
9607
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10410
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10138
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...
1
7674
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
5700
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4353
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
3027
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.