Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have created a web browser in glade / python and what i'm wanting to do is get HTTP:// to load automatically. Just because at the moment whenever i go to a website i have to type the HTTP:// and if i do not type this then the website does not open and i get a error message.

could anyone please help me out with the code or a way to do this please.

share|improve this question
It works in Firefox. Have you tried Ctrl+Enter? – Mitch Apr 17 '13 at 17:36
Just add a list of protocols (http, https, ftp, etc) and require that the leading blob be one of them. If it's not prepend the default to the string. – RobotHumans Apr 17 '13 at 18:03
up vote 3 down vote accepted

Assuming the address entry is called address_entry, try it like this:

url = address_entry.get_text()
if not "://" in url:
    # Is http a sane prefix?
    url = "http://" + url
share|improve this answer
cheers for that i just got it working tonight i was playing about with some code and it started working."http://" + url) that is the code that got it to work for me – DriftedMass Apr 18 '13 at 23:02
@DriftedMass: that doesn't sound like a solution to me. What if the user already typed http://? You end up with an invalid http:// – Timo Apr 19 '13 at 8:30
python is so nice! – don.joey Apr 19 '13 at 10:31
So if the user had already typed http:// how do you suggest that i cancel out the script running the http:// bit? – DriftedMass Apr 19 '13 at 12:23
@DriftedMass: see my answer. It will only add http:// if the string :// isn't found in the url. – Timo Apr 19 '13 at 12:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.